1448
|
1 package goodjava.logger;
|
|
2
|
|
3 import java.util.Map;
|
|
4 import java.util.HashMap;
|
|
5
|
|
6
|
1450
|
7 public final class GoodLoggerFactory {
|
|
8 private GoodLoggerFactory() {} // never
|
1448
|
9
|
1454
|
10 public static final Appender DEFAULT_APPENDER;
|
1450
|
11 public static final Configurer DEFAULT_CONFIGURER;
|
|
12 static {
|
|
13 Layout layout = new ListLayout(Layouts.LEVEL," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
|
1454
|
14 DEFAULT_APPENDER = new ConsoleAppender(layout,System.err);
|
|
15 DEFAULT_CONFIGURER = new SimpleConfigurer(Level.INFO,DEFAULT_APPENDER);
|
1450
|
16 }
|
|
17 private static final Map<String,GoodLogger> map = new HashMap<String,GoodLogger>();
|
|
18 private static Configurer configurer = DEFAULT_CONFIGURER;
|
|
19
|
|
20 public static synchronized GoodLogger getLogger(String name) {
|
1448
|
21 GoodLogger logger = map.get(name);
|
|
22 if( logger == null ) {
|
|
23 logger = new GoodLogger(name);
|
1450
|
24 configurer.configure(logger);
|
1448
|
25 map.put(name,logger);
|
|
26 }
|
|
27 return logger;
|
|
28 }
|
1450
|
29
|
|
30 public static synchronized Configurer getConfigurer() {
|
|
31 return configurer;
|
|
32 }
|
|
33
|
|
34 public static synchronized void setConfigurer(Configurer configurer) {
|
|
35 GoodLoggerFactory.configurer = configurer;
|
|
36 for( GoodLogger logger : map.values() ) {
|
|
37 configurer.configure(logger);
|
|
38 }
|
|
39 }
|
|
40
|
1448
|
41 }
|