package org.nutz.log.impl;

/**
 * 默认的Log,输出到System.err.
 * 
 * @author Young(sunonfire@gmail.com)
 * @author Wendal(wendal1985@gmail.com)
 */
public class SystemLog extends AbstractLog {

	private static SystemLog systemLog = new SystemLog();

	static SystemLog me() {
		return systemLog;
	}

	private SystemLog() {
		isInfoEnabled = true;
	}

	public void debug(Object message, Throwable t) {
		if (isDebugEnabled())
			printOut(message, t);
	}

	public void error(Object message, Throwable t) {
		if (isErrorEnabled())
			errorOut(message, t);
	}

	public void fatal(Object message, Throwable t) {
		if (isFatalEnabled())
			errorOut(message, t);
	}

	public void info(Object message, Throwable t) {
		if (isInfoEnabled())
			printOut(message, t);
	}

	public void trace(Object message, Throwable t) {
		if (isTraceEnabled())
			printOut(message, t);
	}

	public void warn(Object message, Throwable t) {
		if (isWarnEnabled())
			errorOut(message, t);
	}

	private void printOut(Object message, Throwable t) {
		System.out.println(message);
		if (t != null)
			t.printStackTrace(System.out);
	}

	private void errorOut(Object message, Throwable t) {
		System.err.println(message);
		if (t != null)
			t.printStackTrace(System.err);
	}

	@Override
	protected void log(int level, Object message, Throwable tx) {
		switch (level) {
		case LEVEL_FATAL:
			errorOut(message, null);
			break;
		case LEVEL_ERROR:
			errorOut(message, null);
			break;
		case LEVEL_WARN:
			errorOut(message, null);
			break;
		case LEVEL_INFO:
			printOut(message, null);
			break;
		case LEVEL_DEBUG:
			printOut(message, null);
			break;
		case LEVEL_TRACE:
			printOut(message, null);
			break;
		default:
			break;
		}
	}

}

@@ -201,16 +201,22 @@
 private 
+final 
 static S
@@ -1430,36 +1430,34 @@
 rorOut(message, 
-null
+tx
 );%0D%0A%09%09%09break;%0D%0A%09
@@ -1489,36 +1489,34 @@
 rorOut(message, 
-null
+tx
 );%0D%0A%09%09%09break;%0D%0A%09
@@ -1547,36 +1547,34 @@
 rorOut(message, 
-null
+tx
 );%0D%0A%09%09%09break;%0D%0A%09
@@ -1605,36 +1605,34 @@
 intOut(message, 
-null
+tx
 );%0D%0A%09%09%09break;%0D%0A%09
@@ -1664,36 +1664,34 @@
 intOut(message, 
-null
+tx
 );%0D%0A%09%09%09break;%0D%0A%09
@@ -1731,20 +1731,18 @@
 essage, 
-null
+tx
 );%0D%0A%09%09%09b

修正SystemLog一个潜在的问题.