diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/goodjava/logger/GoodLogger.java	Sun Feb 23 18:14:32 2020 -0700
@@ -0,0 +1,72 @@
+package goodjava.logger;
+
+import goodjava.logging.Logger;
+
+
+public final class GoodLogger implements Logger {
+	public final String name;
+	public volatile int level = Level.INFO;
+	public volatile Appender appender = DEFAULT_APPENDER;
+
+	GoodLogger(String name) {
+		this.name = name;
+	}
+
+	private void log(int level,String msg,Throwable t) {
+		if( level < this.level )
+			return;
+		LoggingEvent event = new LoggingEvent(this,level,msg,t);
+		appender.append(event);
+	}
+
+
+	@Override public void error(String msg) {
+		error(msg,null);
+	}
+
+	@Override public void error(String msg,Throwable t) {
+		log(Level.ERROR,msg,t);
+	}
+
+	@Override public void warn(String msg) {
+		warn(msg,null);
+	}
+
+	@Override public void warn(String msg,Throwable t) {
+		log(Level.WARN,msg,t);
+	}
+
+	@Override public void info(String msg) {
+		info(msg,null);
+	}
+
+	@Override public void info(String msg,Throwable t) {
+		log(Level.INFO,msg,t);
+	}
+
+	@Override public boolean isInfoEnabled() {
+		return isEnabled(Level.INFO);
+	}
+
+	@Override public void debug(String msg) {
+		debug(msg,null);
+	}
+
+	@Override public void debug(String msg,Throwable t) {
+		log(Level.DEBUG,msg,t);
+	}
+
+	@Override public boolean isDebugEnabled() {
+		return isEnabled(Level.DEBUG);
+	}
+
+	private boolean isEnabled(int level) {
+		return true;
+	}
+
+
+	private static final Layout DEFAULT_LAYOUT 
+		= new ListLayout(Layouts.LEVEL," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE);
+
+	private static final WriterAppender DEFAULT_APPENDER = new ConsoleAppender(DEFAULT_LAYOUT,System.err);
+}