1 package org.slf4j.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.logwrapper.LogLevelRecorder;
23 import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;
24 import org.slf4j.Logger;
25
26 import java.util.Optional;
27
28
29
30
31 public class MavenLoggerFactory extends SimpleLoggerFactory implements MavenSlf4jWrapperFactory
32 {
33 private LogLevelRecorder logLevelRecorder = null;
34
35 @Override
36 public void setLogLevelRecorder( LogLevelRecorder logLevelRecorder )
37 {
38 if ( this.logLevelRecorder != null )
39 {
40 throw new IllegalStateException( "LogLevelRecorder has already been set." );
41 }
42
43 this.logLevelRecorder = logLevelRecorder;
44 }
45
46 @Override
47 public Optional<LogLevelRecorder> getLogLevelRecorder()
48 {
49 return Optional.ofNullable( logLevelRecorder );
50 }
51
52
53
54
55 @Override
56 public Logger getLogger( String name )
57 {
58 Logger simpleLogger = loggerMap.get( name );
59 if ( simpleLogger != null )
60 {
61 return simpleLogger;
62 }
63 else
64 {
65 Logger newInstance = getNewLoggingInstance( name );
66 Logger oldInstance = loggerMap.putIfAbsent( name, newInstance );
67 return oldInstance == null ? newInstance : oldInstance;
68 }
69 }
70
71 private Logger getNewLoggingInstance( String name )
72 {
73 if ( logLevelRecorder == null )
74 {
75 return new MavenSimpleLogger( name );
76 }
77 else
78 {
79 return new MavenFailOnSeverityLogger( name, logLevelRecorder );
80 }
81 }
82 }