1454
|
1 package goodjava.logger.examples;
|
|
2
|
|
3 import goodjava.logging.Logger;
|
|
4 import goodjava.logging.LoggerFactory;
|
|
5 import goodjava.logger.Layout;
|
|
6 import goodjava.logger.Layouts;
|
|
7 import goodjava.logger.DateLayout;
|
|
8 import goodjava.logger.ListLayout;
|
|
9 import goodjava.logger.Appender;
|
|
10 import goodjava.logger.RollingFileAppender;
|
|
11 import goodjava.logger.LevelAppender;
|
|
12 import goodjava.logger.ListAppender;
|
|
13 import goodjava.logger.Level;
|
|
14 import goodjava.logger.SimpleConfigurer;
|
|
15 import goodjava.logger.GoodLoggerFactory;
|
|
16 import java.io.IOException;
|
|
17
|
|
18
|
|
19 public class RollingFiles {
|
|
20 private static final Logger logger = LoggerFactory.getLogger(RollingFiles.class);
|
|
21
|
|
22 public static void main(String[] args) throws Exception {
|
|
23 config();
|
|
24 logger.debug("test debug");
|
|
25 logger.info("test info");
|
|
26 logger.warn("test warn");
|
|
27 logger.error("test error");
|
|
28 }
|
|
29
|
|
30 static void config() throws IOException {
|
|
31 Layout layout = new ListLayout(new DateLayout("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
|
|
32 Appender error = appender(layout,"error.log",Level.ERROR);
|
|
33 Appender warn = appender(layout,"warn.log",Level.WARN);
|
|
34 Appender info = appender(layout,"info.log",Level.INFO);
|
|
35 Appender appender = new ListAppender(error,warn,info);
|
|
36 GoodLoggerFactory.setConfigurer( new SimpleConfigurer(Level.INFO,appender) );
|
|
37 }
|
|
38
|
|
39 static Appender appender(Layout layout,String fileName,int level) throws IOException {
|
|
40 RollingFileAppender appender = new RollingFileAppender(layout,fileName);
|
|
41 return new LevelAppender(appender,level);
|
|
42 }
|
|
43 }
|