00001
00005 package edu.mit.csail.sdg.squander.log;
00006
00007 import java.io.PrintStream;
00008
00009 import edu.mit.csail.sdg.squander.options.GlobalOptions;
00010
00016 public class Log {
00017
00018 public enum Level {
00019 ALL, TRACE, DEBUG, LOG, WARN, ERROR, FATAL, NONE
00020 }
00021
00022 private static PrintStream out = System.out;
00023
00024
00025
00026
00027
00028
00029
00030
00031 public static void trace(String msg) {
00032 trace(msg.replaceAll("%", "%%"), new Object[0]);
00033 }
00034
00035 public static void trace(String msg, Object... args) {
00036 myLog(Level.TRACE, msg, args);
00037 }
00038
00039 public static void debug(String msg) {
00040 debug(msg.replaceAll("%", "%%"), new Object[0]);
00041 }
00042
00043 public static void debug(String msg, Object... args) {
00044 myLog(Level.DEBUG, msg, args);
00045 }
00046
00047 public static void log(String msg) {
00048 log(msg.replaceAll("%", "%%"), new Object[0]);
00049 }
00050
00051 public static void log(String msg, Object... args) {
00052 myLog(Level.LOG, msg, args);
00053 }
00054
00055 public static void warn(String msg) {
00056 warn(msg.replaceAll("%", "%%"), new Object[0]);
00057 }
00058
00059 public static void warn(String msg, Object... args) {
00060 myLog(Level.WARN, msg, args);
00061 }
00062
00063 public static void error(String msg, Object... args) {
00064 myLog(Level.ERROR, msg, args);
00065 }
00066
00067 private static void myLog(Level logLevel, String msg, Object... args) {
00068 if (logLevel.ordinal() < GlobalOptions.INSTANCE.log_level.ordinal())
00069 return;
00070 msg = String.format(msg, args);
00071 out.println(String.format("[%s] %s", logLevel,
00072 msg.replaceAll("\\n", String.format("\n[%s] ", logLevel))));
00073 }
00074
00075 }