Mercurial Hosting > luan
comparison src/goodjava/logging/LoggerFactory.java @ 1448:6fc083e1d08c
start logger
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 23 Feb 2020 18:14:32 -0700 |
parents | 27efb1fcbcb5 |
children | 219f2b937f2b |
comparison
equal
deleted
inserted
replaced
1447:851b9a48cc44 | 1448:6fc083e1d08c |
---|---|
1 package goodjava.logging; | 1 package goodjava.logging; |
2 | 2 |
3 | 3 |
4 public abstract class LoggerFactory { | 4 public final class LoggerFactory { |
5 public static LoggerFactory implementation = new Log4jFactory(); | 5 public static final ILoggerFactory implementation; |
6 | 6 static { |
7 protected abstract Logger getLoggerImpl(Class cls); | 7 String s = System.getProperty("goodjava.logger","goodjava.logging.Log4jFactory"); |
8 protected abstract Logger getLoggerImpl(String name); | 8 try { |
9 | 9 implementation = (ILoggerFactory)Class.forName(s).newInstance(); |
10 public static Logger getLogger(Class cls) { | 10 } catch(ClassNotFoundException e) { |
11 return implementation.getLoggerImpl(cls); | 11 throw new RuntimeException(e); |
12 } catch(InstantiationException e) { | |
13 throw new RuntimeException(e); | |
14 } catch(IllegalAccessException e) { | |
15 throw new RuntimeException(e); | |
16 } | |
12 } | 17 } |
13 | 18 |
14 public static Logger getLogger(String name) { | 19 public static Logger getLogger(String name) { |
15 return implementation.getLoggerImpl(name); | 20 return implementation.getLogger(name); |
21 } | |
22 | |
23 public static Logger getLogger(Class cls) { | |
24 return getLogger(cls.getName()); | |
16 } | 25 } |
17 } | 26 } |