annotate src/goodjava/logger/GoodLogger.java @ 1712:36c28be6d432

improve html and bbcode
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Jul 2022 22:14:21 -0600
parents 329197048ff0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.logger;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import goodjava.logging.Logger;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 public final class GoodLogger implements Logger {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 public final String name;
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
8 public volatile int level;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1448
diff changeset
9 public volatile Appender appender;
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
1594
329197048ff0 add DailyRollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1450
diff changeset
11 public GoodLogger(String name) {
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 this.name = name;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 private void log(int level,String msg,Throwable t) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 if( level < this.level )
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 return;
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 LoggingEvent event = new LoggingEvent(this,level,msg,t);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 appender.append(event);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 @Override public void error(String msg) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 error(msg,null);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 @Override public void error(String msg,Throwable t) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 log(Level.ERROR,msg,t);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 @Override public void warn(String msg) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 warn(msg,null);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 @Override public void warn(String msg,Throwable t) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 log(Level.WARN,msg,t);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 @Override public void info(String msg) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 info(msg,null);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 @Override public void info(String msg,Throwable t) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 log(Level.INFO,msg,t);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 @Override public boolean isInfoEnabled() {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 return isEnabled(Level.INFO);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 @Override public void debug(String msg) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 debug(msg,null);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 @Override public void debug(String msg,Throwable t) {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 log(Level.DEBUG,msg,t);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 @Override public boolean isDebugEnabled() {
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 return isEnabled(Level.DEBUG);
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 private boolean isEnabled(int level) {
1594
329197048ff0 add DailyRollingFileAppender
Franklin Schmidt <fschmidt@gmail.com>
parents: 1450
diff changeset
64 return level >= this.level;
1448
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 }
6fc083e1d08c start logger
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 }