1 6 package org.jfox.ioc.logger; 7 8 import org.apache.log4j.Level; 9 10 13 14 public class Logger { 15 16 private org.apache.log4j.Logger logger; 17 18 static { 19 _init(); 20 } 21 22 25 private static void _init() { 26 LoggerMananger.class.getName(); 27 } 28 29 public static Logger getLogger(String name) { 30 return new Logger(name); 31 } 32 33 public static Logger getLogger(Class clz) { 34 return new Logger(clz.getName()); 35 } 36 37 private Logger(String name) { 38 logger = org.apache.log4j.Logger.getLogger(name); 39 } 40 41 46 public void trace(Object message) { 47 logger.log(Level.DEBUG, message); 48 } 49 50 51 57 public void trace(Object message, Throwable t) { 58 logger.log(Level.DEBUG, message, t); 59 } 60 61 66 public void debug(Object message) { 67 logger.log(Level.DEBUG, message); 68 } 69 70 71 77 public void debug(Object message, Throwable t) { 78 logger.log(Level.DEBUG, message, t); 79 } 80 81 82 87 public void info(Object message) { 88 logger.log(Level.INFO, message); 89 } 90 91 92 98 public void info(Object message, Throwable t) { 99 logger.log(Level.INFO, message, t); 100 } 101 102 103 108 public void warn(Object message) { 109 logger.log(Level.WARN, message); 110 } 111 112 113 119 public void warn(Object message, Throwable t) { 120 logger.log(Level.WARN, message, t); 121 } 122 123 124 129 public void error(Object message) { 130 logger.log(Level.ERROR, message); 131 } 132 133 134 140 public void error(Object message, Throwable t) { 141 logger.log(Level.ERROR, message, t); 142 } 143 144 145 150 public void fatal(Object message) { 151 logger.log(Level.FATAL, message); 152 } 153 154 155 161 public void fatal(Object message, Throwable t) { 162 logger.log(Level.FATAL, message, t); 163 } 164 165 public boolean isTraceEnabled() { 166 return true; 167 } 168 169 public boolean isDebugEnabled() { 170 return logger.isDebugEnabled(); 171 } 172 173 public boolean isInfoEnabled() { 174 return logger.isInfoEnabled(); 175 } 176 177 public boolean isWarnEnabled() { 178 return logger.isEnabledFor(Level.WARN); 179 180 } 181 182 public boolean isErrorEnabled() { 183 return logger.isEnabledFor(Level.ERROR); 184 } 185 186 public boolean isFatalEnabled() { 187 return logger.isEnabledFor(Level.FATAL); 188 } 189 190 public static void main(String [] args) { 191 Logger logger = Logger.getLogger("test"); 192 logger.info("test message"); 193 194 } 195 } 196 197 | Popular Tags |