org/sonews/util/Log.java
changeset 15 f2293e8566f5
parent 3 2fdc9cc89502
child 16 5a4a41cfc0a3
     1.1 --- a/org/sonews/util/Log.java	Thu Aug 20 16:57:38 2009 +0200
     1.2 +++ b/org/sonews/util/Log.java	Thu Aug 20 18:41:21 2009 +0200
     1.3 @@ -18,7 +18,11 @@
     1.4  
     1.5  package org.sonews.util;
     1.6  
     1.7 -import java.util.Date;
     1.8 +import java.util.logging.Level;
     1.9 +import java.util.logging.LogManager;
    1.10 +import java.util.logging.Logger;
    1.11 +import java.util.logging.SimpleFormatter;
    1.12 +import java.util.logging.StreamHandler;
    1.13  import org.sonews.config.Config;
    1.14  
    1.15  /**
    1.16 @@ -28,32 +32,26 @@
    1.17   */
    1.18  public class Log
    1.19  {
    1.20 -  
    1.21 -  public static boolean isDebug()
    1.22 +
    1.23 +  public static final String MAIN = "main";
    1.24 +
    1.25 +  static
    1.26    {
    1.27 -    // We must use FileConfig here otherwise we come
    1.28 -    // into hell's kittchen when using the Logger within the
    1.29 -    // Database class.
    1.30 -    return Config.inst().get(Config.DEBUG, false);
    1.31 +    Logger mainLogger = Logger.getLogger(MAIN);
    1.32 +    StreamHandler handler = new StreamHandler(System.out, new SimpleFormatter());
    1.33 +    handler.setLevel(Level.parse(Config.inst().get(Config.LOGLEVEL, "INFO")));
    1.34 +    mainLogger.addHandler(handler);
    1.35 +    LogManager.getLogManager().addLogger(mainLogger);
    1.36    }
    1.37 -  
    1.38 -  /**
    1.39 -   * Writes the given message to the debug output.
    1.40 -   * @param msg A String message or an object.
    1.41 -   * @param If true this message is only shown if debug mode is enabled.
    1.42 -   */
    1.43 -  public static void msg(final Object msg, boolean debug)
    1.44 +
    1.45 +  public static Logger get()
    1.46    {
    1.47 -    if(isDebug() || !debug)
    1.48 -    {
    1.49 -      synchronized(System.out)
    1.50 -      {
    1.51 -        System.out.print(new Date().toString());
    1.52 -        System.out.print(": ");
    1.53 -        System.out.println(msg);
    1.54 -        System.out.flush();
    1.55 -      }
    1.56 -    }
    1.57 +    return get(MAIN);
    1.58 +  }
    1.59 +
    1.60 +  public static Logger get(String name)
    1.61 +  {
    1.62 +    return LogManager.getLogManager().getLogger(name);
    1.63    }
    1.64  
    1.65  }