annotate src/goodjava/logger/GoodLoggerFactory.java @ 1550:0dc3be25ad20

use_long_strings
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 03 Oct 2020 23:08:36 -0600
parents 219f2b937f2b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.logger;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.util.Map;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.util.HashMap;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
7 public final class GoodLoggerFactory {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
8 private GoodLoggerFactory() {} // never
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
1454
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 1450
diff changeset
10 public static final Appender DEFAULT_APPENDER;
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
11 public static final Configurer DEFAULT_CONFIGURER;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
12 static {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
13 Layout layout = new ListLayout(Layouts.LEVEL," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
1454
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 1450
diff changeset
14 DEFAULT_APPENDER = new ConsoleAppender(layout,System.err);
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 1450
diff changeset
15 DEFAULT_CONFIGURER = new SimpleConfigurer(Level.INFO,DEFAULT_APPENDER);
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
16 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
17 private static final Map<String,GoodLogger> map = new HashMap<String,GoodLogger>();
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
18 private static Configurer configurer = DEFAULT_CONFIGURER;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
19
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
20 public static synchronized GoodLogger getLogger(String name) {
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 GoodLogger logger = map.get(name);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 if( logger == null ) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 logger = new GoodLogger(name);
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
24 configurer.configure(logger);
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 map.put(name,logger);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 return logger;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 }
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
29
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
30 public static synchronized Configurer getConfigurer() {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
31 return configurer;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
32 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
33
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
34 public static synchronized void setConfigurer(Configurer configurer) {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
35 GoodLoggerFactory.configurer = configurer;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
36 for( GoodLogger logger : map.values() ) {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
37 configurer.configure(logger);
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
38 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
39 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
40
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 }