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