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