annotate src/goodjava/logger/GoodLoggerFactory.java @ 1453:928be2a4d565

fix postgres backup
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 02 Mar 2020 15:09:10 -0700
parents 28b1ddacfad3
children 219f2b937f2b
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
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
10 public static final Configurer DEFAULT_CONFIGURER;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
11 static {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
12 Layout layout = new ListLayout(Layouts.LEVEL," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
13 Appender appender = new ConsoleAppender(layout,System.err);
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
14 DEFAULT_CONFIGURER = new SimpleConfigurer(Level.INFO,appender);
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
15 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
16 private static final Map<String,GoodLogger> map = new HashMap<String,GoodLogger>();
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
17 private static Configurer configurer = DEFAULT_CONFIGURER;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
18
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
19 public static synchronized GoodLogger getLogger(String name) {
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 GoodLogger logger = map.get(name);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 if( logger == null ) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 logger = new GoodLogger(name);
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
23 configurer.configure(logger);
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 map.put(name,logger);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 return logger;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 }
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
28
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
29 public static synchronized Configurer getConfigurer() {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
30 return configurer;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
31 }
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 public static synchronized void setConfigurer(Configurer configurer) {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
34 GoodLoggerFactory.configurer = configurer;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
35 for( GoodLogger logger : map.values() ) {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
36 configurer.configure(logger);
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
37 }
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
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 }