1 package org.fax4j.common;
2
3 import java.util.Map;
4 import org.fax4j.util.LibraryConfigurationLoader;
5 import org.fax4j.util.ReflectionHelper;
6
7
8
9
10
11
12
13
14 public final class LoggerManager {
15
16 private Logger logger;
17
18 private static final LoggerManagererManager">LoggerManager INSTANCE = new LoggerManager();
19
20 public static final String LOGGER_CLASS_NAME_PROPERTY_KEY = "org.fax4j.logger.class.name";
21
22 public static final String LOGGER_LOG_LEVEL_PROPERTY_KEY = "org.fax4j.logger.log.level";
23
24
25
26
27 private LoggerManager() {
28 super();
29
30
31 this.initializeLogger();
32 }
33
34
35
36
37
38
39 public static LoggerManager getInstance() {
40 return LoggerManager.INSTANCE;
41 }
42
43
44
45
46 private void initializeLogger() {
47
48 Map<String, String> systemConfiguration = LibraryConfigurationLoader.getSystemConfiguration();
49
50
51 this.createLogger(systemConfiguration);
52 }
53
54
55
56
57
58
59 public Logger getLogger() {
60 return this.logger;
61 }
62
63
64
65
66
67
68
69
70
71
72 private void createLogger(Map<String, String> systemConfiguration) {
73
74 String className = systemConfiguration.get(LoggerManager.LOGGER_CLASS_NAME_PROPERTY_KEY);
75 if (className == null || className.length() == 0) {
76 className = SimpleLogger.class.getName();
77 }
78
79
80 Logger/org/fax4j/common/Logger.html#Logger">Logger loggerInstance = (Logger) ReflectionHelper.createInstance(className);
81
82
83 loggerInstance.setLogLevel(LogLevel.NONE);
84
85
86 String logLevelName = systemConfiguration.get(LoggerManager.LOGGER_LOG_LEVEL_PROPERTY_KEY);
87
88
89 if (logLevelName != null) {
90 if (logLevelName.equalsIgnoreCase(LogLevel.ERROR.getName())) {
91 loggerInstance.setLogLevel(LogLevel.ERROR);
92 } else if (logLevelName.equalsIgnoreCase(LogLevel.INFO.getName())) {
93 loggerInstance.setLogLevel(LogLevel.INFO);
94 } else if (logLevelName.equalsIgnoreCase(LogLevel.DEBUG.getName())) {
95 loggerInstance.setLogLevel(LogLevel.DEBUG);
96 }
97 }
98
99
100 this.logger = loggerInstance;
101 }
102 }