comparison src/goodjava/logger/GoodLogger.java @ 1448:6fc083e1d08c

start logger
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Feb 2020 18:14:32 -0700
parents
children 28b1ddacfad3
comparison
equal deleted inserted replaced
1447:851b9a48cc44 1448:6fc083e1d08c
1 package goodjava.logger;
2
3 import goodjava.logging.Logger;
4
5
6 public final class GoodLogger implements Logger {
7 public final String name;
8 public volatile int level = Level.INFO;
9 public volatile Appender appender = DEFAULT_APPENDER;
10
11 GoodLogger(String name) {
12 this.name = name;
13 }
14
15 private void log(int level,String msg,Throwable t) {
16 if( level < this.level )
17 return;
18 LoggingEvent event = new LoggingEvent(this,level,msg,t);
19 appender.append(event);
20 }
21
22
23 @Override public void error(String msg) {
24 error(msg,null);
25 }
26
27 @Override public void error(String msg,Throwable t) {
28 log(Level.ERROR,msg,t);
29 }
30
31 @Override public void warn(String msg) {
32 warn(msg,null);
33 }
34
35 @Override public void warn(String msg,Throwable t) {
36 log(Level.WARN,msg,t);
37 }
38
39 @Override public void info(String msg) {
40 info(msg,null);
41 }
42
43 @Override public void info(String msg,Throwable t) {
44 log(Level.INFO,msg,t);
45 }
46
47 @Override public boolean isInfoEnabled() {
48 return isEnabled(Level.INFO);
49 }
50
51 @Override public void debug(String msg) {
52 debug(msg,null);
53 }
54
55 @Override public void debug(String msg,Throwable t) {
56 log(Level.DEBUG,msg,t);
57 }
58
59 @Override public boolean isDebugEnabled() {
60 return isEnabled(Level.DEBUG);
61 }
62
63 private boolean isEnabled(int level) {
64 return true;
65 }
66
67
68 private static final Layout DEFAULT_LAYOUT
69 = new ListLayout(Layouts.LEVEL," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
70
71 private static final WriterAppender DEFAULT_APPENDER = new ConsoleAppender(DEFAULT_LAYOUT,System.err);
72 }