comparison src/goodjava/webserver/handlers/LogHandler.java @ 1733:8b3ad1fb219f

make LogHandler configurable
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 14 Sep 2022 07:51:13 -0600
parents 94ea190714dd
children
comparison
equal deleted inserted replaced
1732:8a6e48371c66 1733:8b3ad1fb219f
19 import goodjava.webserver.Request; 19 import goodjava.webserver.Request;
20 import goodjava.webserver.Response; 20 import goodjava.webserver.Response;
21 21
22 22
23 public final class LogHandler implements Handler { 23 public final class LogHandler implements Handler {
24 private static final Layout layout = new ListLayout(new DateLayout("yyyy-MM-dd:HH:mm:ss")," ",Layouts.MESSAGE,"\n"); 24 public static int level = Level.INFO;
25 public static Layout layout = new ListLayout(new DateLayout("yyyy-MM-dd:HH:mm:ss")," ",Layouts.MESSAGE,"\n");
25 26
26 public static Logger consoleLogger() { 27 public static Logger consoleLogger() {
27 Appender appender = new ConsoleAppender(layout,System.err); 28 Appender appender = new ConsoleAppender(layout,System.err);
28 GoodLogger logger = new GoodLogger("HTTP"); 29 GoodLogger logger = new GoodLogger("HTTP");
29 logger.appender = appender; 30 logger.appender = appender;
30 logger.level = Level.INFO; 31 logger.level = level;
31 return logger; 32 return logger;
32 } 33 }
33 34
34 public static Logger dirLogger(File dir,long deleteAfter) { 35 public static Logger dirLogger(File dir,long deleteAfter) {
35 if( dir.exists() && !dir.isDirectory() ) 36 if( dir.exists() && !dir.isDirectory() )
42 DateFormat fmt = new SimpleDateFormat( "'" + dir + "/'yyyy_MM_dd'.log'" ); 43 DateFormat fmt = new SimpleDateFormat( "'" + dir + "/'yyyy_MM_dd'.log'" );
43 DailyRollingFileAppender appender = new DailyRollingFileAppender(layout,fmt); 44 DailyRollingFileAppender appender = new DailyRollingFileAppender(layout,fmt);
44 appender.deleteAfter = deleteAfter; 45 appender.deleteAfter = deleteAfter;
45 GoodLogger logger = new GoodLogger("HTTP"); 46 GoodLogger logger = new GoodLogger("HTTP");
46 logger.appender = appender; 47 logger.appender = appender;
47 logger.level = Level.INFO; 48 logger.level = level;
48 return logger; 49 return logger;
49 } 50 }
50 51
51 private final Handler handler; 52 private final Handler handler;
52 private final Logger logger; 53 private final Logger logger;