From 1a15797202b29b63a0677041c437bb0dcb559e54 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 13 May 2008 06:50:32 +0000 Subject: [PATCH] add console handler with better line format git-svn-id: http://trooper/svn/projects/jSite/trunk@805 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/util/logging/Logging.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/net/pterodactylus/util/logging/Logging.java b/src/net/pterodactylus/util/logging/Logging.java index 66ca181..9b25ff3 100644 --- a/src/net/pterodactylus/util/logging/Logging.java +++ b/src/net/pterodactylus/util/logging/Logging.java @@ -21,7 +21,10 @@ package net.pterodactylus.util.logging; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; +import java.util.logging.ConsoleHandler; +import java.util.logging.Formatter; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -75,6 +78,24 @@ public class Logging { hierarchyRootName = hierarchyName; Logger rootLogger = Logger.getLogger(hierarchyName); rootLogger.addHandler(logHandler); + Handler consoleHandler = new ConsoleHandler(); + consoleHandler.setLevel(Level.ALL); + consoleHandler.setFormatter(new Formatter() { + private StringBuffer recordBuffer = new StringBuffer(); + /** + * {@inheritDoc} + */ + @Override + public synchronized String format(LogRecord record) { + recordBuffer.setLength(0); + recordBuffer.append(new Date(record.getMillis())).append(' ').append(record.getLevel().getName()).append(' '); + recordBuffer.append(record.getSourceClassName()).append('.').append(record.getSourceMethodName()).append(' '); + recordBuffer.append(record.getMessage()); + recordBuffer.append("\r\n"); + return recordBuffer.toString(); + } + }); + rootLogger.addHandler(consoleHandler); rootLogger.setUseParentHandlers(false); rootLogger.setLevel(Level.ALL); } -- 2.7.4