日期:2014-05-19 浏览次数:20748 次
public static void logOnConsole(Logger log,Exception e){
RootLogger rootLogger = new RootLogger(Level.ERROR);
ConsoleAppender consoleAppender = new ConsoleAppender();
consoleAppender.setTarget("System.out");
PatternLayout patternLayout = new PatternLayout();
patternLayout.setConversionPattern("[ErrorMessage] %d - [%t] %-5p %c - %m%n");
consoleAppender.setLayout(patternLayout);
LoggingEvent loggingEvent = new LoggingEvent(log.getName(), log, Level.ERROR, "AAAAAA", e);
rootLogger.addAppender(consoleAppender);
rootLogger.callAppenders(loggingEvent);
}
Logger log = Logger.getRootLogger();
log.setLevel(Level.DEBUG);
ConsoleAppender ca = new ConsoleAppender();
ca.setName("aaa");
ca.setLayout(new PatternLayout(
"%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n"));
ca.setWriter(new PrintWriter(System.out));
//如果是文件是RollingFileAppender:setWriter(new PrintWriter(new File("F:/test/_debug.log")));
log.addAppender(ca);
Logger caLog = Logger.getLogger(Log.class);
caLog.debug("aaaaaaaaa");