Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 
 package base.log;
 
public class SimpleClassLogFormat extends Formatter {
	protected final DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	public String format(LogRecord record) {
		String entry = .format(new Date(record.getMillis()))+" "+record.getLevel().getName()+" "+record.getSourceClassName()+" "+record.getMessage();
		if(record.getThrown() != null){
			entry = entry + " - " + exceptionToString(record.getThrown());
			if(record.getThrown().getCause() != null) {
				entry = entry + " - Caused by " + exceptionToString(record.getThrown().getCause());
				if(record.getThrown().getCause().getCause() != null) {
					entry = entry + " - Caused by " + exceptionToString(record.getThrown().getCause().getCause());
				}
			}
		}
		return entry + "\n";
	}
		String msg = t.getClass().getName() + ": " + t.getMessage() + " -";
		final StackTraceElement[] stackTrace = t.getStackTrace();
		for(StackTraceElement element : stackTrace) {
			String className = element.getClassName();
			msg = msg + " " + className + "." + element.getMethodName() + "():" + element.getLineNumber() + " ";
			if(className.startsWith("sun.") || className.startsWith("java.")) {
				break;
			}
		}
		return msg;
	}
	public String getHead(Handler h) {
		return "";
	}
	public String getTail(Handler h) {
		return "";
	}
New to GrepCode? Check out our FAQ X