From 8cffcf5b5783549d0aa32344dbfd0343245eb02e Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 26 Nov 2007 14:43:42 +0000 Subject: [PATCH] * Reimplement Jetty log sedating by introducing a new private Log class that reduces the log verbosity for levels DEBUG and TRACE. This is a fix for the fix for bug 560 , which resulted in Jetty logfiles to be written to a subdirectory called "console". --- src/helma/util/Logger.java | 99 ++++++++++++++++++++++++++++++++++++- src/helma/util/Logging.java | 15 ++++-- 2 files changed, 108 insertions(+), 6 deletions(-) diff --git a/src/helma/util/Logger.java b/src/helma/util/Logger.java index aa6ae823..c24554af 100644 --- a/src/helma/util/Logger.java +++ b/src/helma/util/Logger.java @@ -55,6 +55,9 @@ public class Logger implements Log { // periods of inactivity long lastMessage = System.currentTimeMillis(); + // sedated log instance for jetty + private Log sedatedLog = new SedatedLog(); + /** * zero argument constructor, only here for FileLogger subclass */ @@ -88,7 +91,7 @@ public class Logger implements Log { else if ("error".equalsIgnoreCase(level)) logLevel = ERROR; else if ("fatal".equalsIgnoreCase(level)) - logLevel = FATAL; + logLevel = FATAL; } /** @@ -302,4 +305,98 @@ public class Logger implements Log { } } + /** + * return a "quiet" version of this log that routes debug() output to trace() + * @return a possibly less verbose version of this log. + */ + protected Log getSedatedLog() { + return sedatedLog; + } + + /* + * A inner class that "calms down" logging output by routing debug() output + * to trace(). This is useful for software like Jetty, which has really + * verbose output at DEBUG level (dumps whole HTTP request and response headers). + * You can enable that output by setting the log level to TRACE. + */ + class SedatedLog implements Log { + + public void debug(Object o) { + // Route debug() to trace() + Logger.this.trace(o); + } + + public void debug(Object o, Throwable t) { + // Route debug() to trace() + Logger.this.trace(o, t); + } + + public void error(Object o) { + Logger.this.error(o); + } + + public void error(Object o, Throwable t) { + Logger.this.error(o, t); + } + + public void fatal(Object o) { + Logger.this.fatal(o); + } + + public void fatal(Object o, Throwable t) { + Logger.this.fatal(o, t); + } + + public void info(Object o) { + Logger.this.info(o); + } + + public void info(Object o, Throwable t) { + Logger.this.info(o, t); + } + + public void trace(Object o) { + // swallow trace() + } + + public void trace(Object o, Throwable t) { + // swallow trace() + } + + public void warn(Object o) { + Logger.this.warn(o); + } + + public void warn(Object o, Throwable t) { + Logger.this.warn(o, t); + } + + public boolean isDebugEnabled() { + // Route debug() to trace() + return Logger.this.isTraceEnabled(); + } + + public boolean isErrorEnabled() { + return Logger.this.isErrorEnabled(); + } + + public boolean isFatalEnabled() { + return Logger.this.isFatalEnabled(); + } + + public boolean isInfoEnabled() { + return Logger.this.isInfoEnabled(); + } + + public boolean isTraceEnabled() { + // swallow trace() + return false; + } + + public boolean isWarnEnabled() { + return Logger.this.isWarnEnabled(); + } + + } + } diff --git a/src/helma/util/Logging.java b/src/helma/util/Logging.java index 45d04459..51e9630f 100644 --- a/src/helma/util/Logging.java +++ b/src/helma/util/Logging.java @@ -63,11 +63,16 @@ public class Logging extends LogFactory { if (logname == null) { throw new LogConfigurationException("No logname specified!"); } - - if ("console".equals(logdir) && !logname.startsWith("org.mortbay.")) { - return getConsoleLog(); + if ("console".equals(logdir)) { + if (logname.startsWith("org.mortbay.")) + return getConsoleLog().getSedatedLog(); + else + return getConsoleLog(); } else { - return getFileLog(logname); + if (logname.startsWith("org.mortbay.")) + return getFileLog(logname).getSedatedLog(); + else + return getFileLog(logname); } } @@ -75,7 +80,7 @@ public class Logging extends LogFactory { * Get a logger to System.out. * @return a logger that writes to System.out */ - public static Log getConsoleLog() { + public static Logger getConsoleLog() { ensureRunning(); return consoleLog; }