Refactor logging to fix NullPointerException.
authorcli
Sat, 01 May 2010 18:51:57 +0200
changeset 2960c237bb677a
parent 28 15d14b110240
child 30 146b3275b792
Refactor logging to fix NullPointerException.
org/sonews/util/Log.java
     1.1 --- a/org/sonews/util/Log.java	Sat May 01 14:27:30 2010 +0200
     1.2 +++ b/org/sonews/util/Log.java	Sat May 01 18:51:57 2010 +0200
     1.3 @@ -30,33 +30,28 @@
     1.4   * @author Christian Lins
     1.5   * @since sonews/0.5.0
     1.6   */
     1.7 -public class Log
     1.8 +public class Log extends Logger
     1.9  {
    1.10  
    1.11 -  public static final String MAIN = "main";
    1.12 +  private static Log instance = new Log();
    1.13  
    1.14 -  static
    1.15 +  private Log()
    1.16    {
    1.17 -    Logger mainLogger = Logger.getLogger(MAIN);
    1.18 +    super("org.sonews", null);
    1.19 +
    1.20      StreamHandler handler = new StreamHandler(System.out, new SimpleFormatter());
    1.21      Level level = Level.parse(Config.inst().get(Config.LOGLEVEL, "INFO"));
    1.22      handler.setLevel(level);
    1.23 -    mainLogger.addHandler(handler);
    1.24 -    mainLogger.setLevel(level);
    1.25 -    LogManager.getLogManager().addLogger(mainLogger);
    1.26 +    addHandler(handler);
    1.27 +    setLevel(level);
    1.28 +    LogManager.getLogManager().addLogger(this);
    1.29    }
    1.30  
    1.31    public static Logger get()
    1.32    {
    1.33 -    return get(MAIN);
    1.34 -  }
    1.35 -
    1.36 -  public static Logger get(String name)
    1.37 -  {
    1.38      Level level = Level.parse(Config.inst().get(Config.LOGLEVEL, "INFO"));
    1.39 -    Logger logger = LogManager.getLogManager().getLogger(name);
    1.40 -    logger.setLevel(level);
    1.41 -    return logger;
    1.42 +    instance.setLevel(level);
    1.43 +    return instance;
    1.44    }
    1.45  
    1.46  }