diff --git a/src/zutil/log/Logger.java b/src/zutil/log/Logger.java index f2c1629..ebd398d 100644 --- a/src/zutil/log/Logger.java +++ b/src/zutil/log/Logger.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.logging.Level; import zutil.MultiPrintStream; +import zutil.wrapper.StringOutputStream; /** * This is a logger class @@ -14,13 +15,13 @@ import zutil.MultiPrintStream; */ public class Logger { // This is the global log level - protected static Level global_log_level; + protected static Level global_log_level = Level.WARNING; + // Class Specific log level + protected static HashMap class_log_level; // The OutputStream protected static PrintStream out; // The formatter class that formats the output protected static LogFormatter formatter; - // Class Specific log level - protected static HashMap class_log_level; // The class that is logging private String source; @@ -38,7 +39,7 @@ public class Logger { * @param logging_class is the class that will be displayed as the logger */ public Logger(Class logging_class){ - this(logging_class.getSimpleName()); + this( logging_class.getSimpleName() ); } /** @@ -58,6 +59,20 @@ public class Logger { if(class_log_level == null) class_log_level = new HashMap(); } + + /** + * Sets the global log level + */ + public static void setGlobalLogLevel(Level l){ + global_log_level = l; + } + + /** + * Sets an specific log level for an class + */ + public static void setClassLogLevel(Class c, Level l){ + class_log_level.put(c.getSimpleName(), l); + } /** * @return the parent class other than Logger in the stack @@ -87,6 +102,18 @@ public class Logger { Logger.out = out; } + /** + * Logs the given exception + * + * @param level is the severity of the exception + * @param e is the exception + */ + public void printStackTrace(Level level, Exception e){ + StringOutputStream msg = new StringOutputStream(); + e.printStackTrace( new PrintStream(msg) ); + log(level, msg.toString()); + } + /** * Logs an message based on level * diff --git a/src/zutil/log/StandardLogFormatter.java b/src/zutil/log/StandardLogFormatter.java index 4a75087..3558046 100644 --- a/src/zutil/log/StandardLogFormatter.java +++ b/src/zutil/log/StandardLogFormatter.java @@ -19,6 +19,17 @@ public class StandardLogFormatter implements LogFormatter{ public String format(String source, Level level, String msg) { StringBuilder data = new StringBuilder(); + + switch(level.intValue()){ + case /* SEVERE */ 1000: data.append("SEVERE : "); break; + case /* WARNING */ 900 : data.append("WARNING: "); break; + case /* INFO */ 800 : data.append("INFO : "); break; + case /* CONFIG */ 700 : data.append("CONFIG : "); break; + case /* FINE */ 500 : data.append("FINE : "); break; + case /* FINER */ 400 : data.append("FINER : "); break; + case /* FINEST */ 300 : data.append("FINEST : "); break; + } + if( timeStamp && className ){ data.append( getTime() ); data.append( " " );