annotate src/goodjava/logger/examples/RollingFiles.java @ 1731:842a0e0fd8c5

fix repeat stmt
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 02 Sep 2022 10:22:31 -0600
parents 97cc73664ca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1454
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.logger.examples;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import goodjava.logging.Logger;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import goodjava.logging.LoggerFactory;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import goodjava.logger.Layout;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 import goodjava.logger.Layouts;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 import goodjava.logger.DateLayout;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 import goodjava.logger.ListLayout;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 import goodjava.logger.Appender;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 import goodjava.logger.RollingFileAppender;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 import goodjava.logger.LevelAppender;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 import goodjava.logger.ListAppender;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 import goodjava.logger.Level;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 import goodjava.logger.SimpleConfigurer;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 import goodjava.logger.GoodLoggerFactory;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 import java.io.IOException;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 public class RollingFiles {
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 private static final Logger logger = LoggerFactory.getLogger(RollingFiles.class);
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 public static void main(String[] args) throws Exception {
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 config();
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 logger.debug("test debug");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 logger.info("test info");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 logger.warn("test warn");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 logger.error("test error");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 }
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 static void config() throws IOException {
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 Layout layout = new ListLayout(new DateLayout("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
1682
97cc73664ca8 improve RollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1454
diff changeset
32 Appender error = appender(layout,"error",Level.ERROR);
97cc73664ca8 improve RollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1454
diff changeset
33 Appender warn = appender(layout,"warn",Level.WARN);
97cc73664ca8 improve RollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1454
diff changeset
34 Appender info = appender(layout,"info",Level.INFO);
1454
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 Appender appender = new ListAppender(error,warn,info);
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 GoodLoggerFactory.setConfigurer( new SimpleConfigurer(Level.INFO,appender) );
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 }
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38
1682
97cc73664ca8 improve RollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1454
diff changeset
39 static Appender appender(Layout layout,String name,int level) throws IOException {
97cc73664ca8 improve RollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1454
diff changeset
40 String[] fileNames = new String[]{ name+".log", name+"_1.log" };
97cc73664ca8 improve RollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1454
diff changeset
41 RollingFileAppender appender = new RollingFileAppender(layout,fileNames);
1454
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 return new LevelAppender(appender,level);
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 }
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 }