comparison src/goodjava/webserver/handlers/LogHandler.java @ 1600:8a717f0b7f45

add DailyRollingFileAppender.deleteAfter
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 09 Apr 2021 19:44:14 -0600
parents c78d6a4e2d9a
children 94ea190714dd
comparison
equal deleted inserted replaced
1599:f2a663a4ba9e 1600:8a717f0b7f45
29 logger.appender = appender; 29 logger.appender = appender;
30 logger.level = Level.INFO; 30 logger.level = Level.INFO;
31 return logger; 31 return logger;
32 } 32 }
33 33
34 public static Logger dirLogger(File dir) { 34 public static Logger dirLogger(File dir,long deleteAfter) {
35 if( dir.exists() && !dir.isDirectory() ) 35 if( dir.exists() && !dir.isDirectory() )
36 throw new RuntimeException("must be a directory"); 36 throw new RuntimeException("must be a directory");
37 try { 37 try {
38 IoUtils.mkdirs(dir); 38 IoUtils.mkdirs(dir);
39 } catch(IOException e) { 39 } catch(IOException e) {
40 throw new RuntimeException(e); 40 throw new RuntimeException(e);
41 } 41 }
42 DateFormat fmt = new SimpleDateFormat( "'" + dir + "/'yyyy_MM_dd'.log'" ); 42 DateFormat fmt = new SimpleDateFormat( "'" + dir + "/'yyyy_MM_dd'.log'" );
43 Appender appender = new DailyRollingFileAppender(layout,fmt); 43 DailyRollingFileAppender appender = new DailyRollingFileAppender(layout,fmt);
44 appender.deleteAfter = deleteAfter;
44 GoodLogger logger = new GoodLogger("HTTP"); 45 GoodLogger logger = new GoodLogger("HTTP");
45 logger.appender = appender; 46 logger.appender = appender;
46 logger.level = Level.INFO; 47 logger.level = Level.INFO;
47 return logger; 48 return logger;
48 } 49 }