annotate src/goodjava/logger/examples/LogFile.java @ 1830:d72a52232f79

mail - minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 24 Sep 2024 17:17:57 -0600
parents 219f2b937f2b
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.WriterAppender;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 import goodjava.logger.Level;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 import goodjava.logger.SimpleConfigurer;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 import goodjava.logger.GoodLoggerFactory;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 import java.io.FileWriter;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 import java.io.IOException;
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 public class LogFile {
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 private static final Logger logger = LoggerFactory.getLogger(LogFile.class);
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 public static void main(String[] args) throws Exception {
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 config();
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 logger.debug("test debug");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 logger.info("test info");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 logger.warn("test warn");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 logger.error("test error");
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 }
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 static void config() throws IOException {
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 Layout layout = new ListLayout(new DateLayout("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 Appender appender = new WriterAppender(layout,new FileWriter("test.log",true));
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 GoodLoggerFactory.setConfigurer( new SimpleConfigurer(Level.INFO,appender) );
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 }
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 }