From 3ba074ecc8412bbaf67237154fdb3dc6bcf7da34 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 6 Sep 2012 12:33:38 -0700 Subject: [PATCH] Adding .STACKS=(boolean) support to StdErrLog configuration --- .../org/eclipse/jetty/util/log/StdErrLog.java | 102 ++++++++++++++++-- .../test/resources/jetty-logging.properties | 2 + 2 files changed, 95 insertions(+), 9 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java index bc91ddc0c36..28972d78056 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java @@ -27,18 +27,62 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; /** - * StdErr Logging. This implementation of the Logging facade sends all logs to StdErr with minimal formatting. + * StdErr Logging implementation. *

- * If the system property "org.eclipse.jetty.LEVEL" is set to one of the following (ALL, DEBUG, INFO, WARN), then set - * the eclipse jetty root level logger level to that specified level. (Default level is INFO) + * A Jetty {@link Logger} that sends all logs to STDERR ({@link System#err}) with basic formatting. *

- * If the system property "org.eclipse.jetty.util.log.SOURCE" is set, then the source method/file of a log is logged. - * For named debuggers, the system property name+".SOURCE" is checked. If it is not not set, then - * "org.eclipse.jetty.util.log.SOURCE" is used as the default. + * Supports named loggers, and properties based configuration. *

- * If the system property "org.eclipse.jetty.util.log.LONG" is set, then the full, unabbreviated name of the logger is - * used for logging. For named debuggers, the system property name+".LONG" is checked. If it is not not set, then - * "org.eclipse.jetty.util.log.LONG" is used as the default. + * Configuration Properties: + *

+ *
${name|heirarchy}.LEVEL=(ALL|DEBUG|INFO|WARN|OFF)
+ *
+ * Sets the level that the Logger should log at.
+ * Names can be a package name, or a fully qualified class name.
+ * Default: INFO
+ *
+ * Examples: + *
+ *
org.eclipse.jetty.LEVEL=WARN
+ *
indicates that all of the jetty specific classes, in any package that + * starts with org.eclipse.jetty should log at level WARN.
+ *
org.eclipse.jetty.io.ChannelEndPoint.LEVEL=ALL
+ *
indicates that the specific class, ChannelEndPoint, should log all + * logging events that it can generate, including DEBUG, INFO, WARN (and even special + * internally ignored exception cases).
+ *
+ *
+ * + *
${name}.SOURCE=(true|false)
+ *
+ * Logger specific, attempt to print the java source file name and line number + * where the logging event originated from.
+ * Name must be a fully qualified class name (package name hierarchy is not supported + * by this configurable)
+ * Warning: this is a slow operation and will have an impact on performance!
+ * Default: false + *
+ * + *
${name}.STACKS=(true|false)
+ *
+ * Logger specific, control the display of stacktraces.
+ * Name must be a fully qualified class name (package name hierarchy is not supported + * by this configurable)
+ * Default: true + *
+ * + *
org.eclipse.jetty.util.log.stderr.SOURCE=(true|false)
+ *
Special Global Configuration, attempt to print the java source file name and line number + * where the logging event originated from.
+ * Default: false + *
+ * + *
org.eclipse.jetty.util.log.stderr.LONG=(true|false)
+ *
Special Global Configuration, when true, output logging events to STDERR using + * long form, fully qualified class names. when false, use abbreviated package names
+ * Default: false + *
+ *
*/ @ManagedObject("Jetty StdErr Logging Implementation") public class StdErrLog extends AbstractLogger @@ -96,6 +140,17 @@ public class StdErrLog extends AbstractLogger private final String _abbrevname; private boolean _hideStacks = false; + /** + * Obtain a StdErrLog reference for the specified class, a convenience method used most often during testing to allow for control over a specific logger. + *

+ * Must be actively using StdErrLog as the Logger implementation. + * + * @param clazz + * the Class reference for the logger to use. + * @return the StdErrLog logger + * @throws RuntimeException + * if StdErrLog is not the active Logger implementation. + */ public static StdErrLog getLogger(Class clazz) { Logger log = Log.getLogger(clazz); @@ -106,16 +161,35 @@ public class StdErrLog extends AbstractLogger throw new RuntimeException("Logger for " + clazz + " is not of type StdErrLog"); } + /** + * Construct an anonymous StdErrLog (no name). + *

+ * NOTE: Discouraged usage! + */ public StdErrLog() { this(null); } + /** + * Construct a named StdErrLog using the {@link Log} defined properties + * + * @param name + * the name of the logger + */ public StdErrLog(String name) { this(name,__props); } + /** + * Construct a named Logger using the provided properties to configure logger. + * + * @param name + * the name of the logger + * @param props + * the configuration properties + */ public StdErrLog(String name, Properties props) { if (props!=null && props!=__props) @@ -133,6 +207,16 @@ public class StdErrLog extends AbstractLogger { _source = __source; } + + try + { + // allow stacktrace display to be controlled by properties as well + _hideStacks = !Boolean.parseBoolean(props.getProperty(_name + ".STACKS","true")); + } + catch (AccessControlException ignore) + { + /* ignore */ + } } /** diff --git a/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties index a0dcc15718c..14019306aed 100644 --- a/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties @@ -4,6 +4,8 @@ org.eclipse.jetty.LEVEL=WARN org.eclipse.jetty.websocket.LEVEL=WARN # org.eclipse.jetty.websocket.LEVEL=DEBUG # org.eclipse.jetty.websocket.client.TrackingSocket.LEVEL=DEBUG +# Hide the stacktraces +org.eclipse.jetty.websocket.client.internal.io.UpgradeConnection.STACKS=false # See the read/write traffic # org.eclipse.jetty.websocket.io.Frames.LEVEL=DEBUG # org.eclipse.jetty.websocket.io.LEVEL=DEBUG