1 8 9 package mx4j.log; 10 11 16 public class Logger 17 { 18 public static final int TRACE = 0; 19 public static final int DEBUG = TRACE + 10; 20 public static final int INFO = DEBUG + 10; 21 public static final int WARN = INFO + 10; 22 public static final int ERROR = WARN + 10; 23 public static final int FATAL = ERROR + 10; 24 25 private int m_priority = WARN; 26 private String m_category; 27 28 protected Logger() 29 { 30 } 31 32 public void setPriority(int priority) 33 { 34 m_priority = priority; 35 } 36 37 public int getPriority() 38 { 39 return m_priority; 40 } 41 42 public String getCategory() 43 { 44 return m_category; 45 } 46 47 protected void setCategory(String category) 48 { 49 m_category = category; 50 } 51 52 public final boolean isEnabledFor(int priority) 53 { 54 return priority >= getPriority(); 55 } 56 57 public final void fatal(Object message) 58 { 59 log(FATAL, message, null); 60 } 61 62 public final void fatal(Object message, Throwable t) 63 { 64 log(FATAL, message, t); 65 } 66 67 public final void error(Object message) 68 { 69 log(ERROR, message, null); 70 } 71 72 public final void error(Object message, Throwable t) 73 { 74 log(ERROR, message, t); 75 } 76 77 public final void warn(Object message) 78 { 79 log(WARN, message, null); 80 } 81 82 public final void warn(Object message, Throwable t) 83 { 84 log(WARN, message, t); 85 } 86 87 public final void info(Object message) 88 { 89 log(INFO, message, null); 90 } 91 92 public final void info(Object message, Throwable t) 93 { 94 log(INFO, message, t); 95 } 96 97 public final void debug(Object message) 98 { 99 log(DEBUG, message, null); 100 } 101 102 public final void debug(Object message, Throwable t) 103 { 104 log(DEBUG, message, t); 105 } 106 107 public final void trace(Object message) 108 { 109 log(TRACE, message, null); 110 } 111 112 public final void trace(Object message, Throwable t) 113 { 114 log(TRACE, message, t); 115 } 116 117 protected void log(int priority, Object message, Throwable t) 118 { 119 if (isEnabledFor(priority)) 120 { 121 System.out.println(message); 122 if (t != null) 123 { 124 t.printStackTrace(System.out); 125 } 126 } 127 } 128 } 129 | Popular Tags |