Package org.eclipse.jetty.util.log
Class StdErrLog
- java.lang.Object
-
- org.eclipse.jetty.util.log.AbstractLogger
-
- org.eclipse.jetty.util.log.StdErrLog
-
- All Implemented Interfaces:
Logger
@ManagedObject("Jetty StdErr Logging Implementation") public class StdErrLog extends AbstractLogger
StdErr Logging implementation.A Jetty
Logger
that sends all logs to STDERR (System.err
) with basic formatting.Supports named loggers, and properties based configuration.
Configuration Properties:
- ${name|hierarchy}.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 - org.eclipse.jetty.util.log.stderr.ESCAPE=(true|false)
- Global Configuration, when true output logging events to STDERR are always
escaped so that control characters are replaced with '?"; '\r' with '<' and '\n' replaced '|'
Default: true
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
__escape
private static boolean
__long
private static boolean
__source
private static int
__tagpad
protected java.lang.String
_abbrevname
private java.io.PrintStream
_altStream
private int
_configuredLevel
private static DateCache
_dateCache
private boolean
_hideStacks
private int
_level
private java.lang.String
_name
private boolean
_printLongNames
private boolean
_source
private static java.lang.Object[]
EMPTY_ARGS
private static java.lang.String
EOL
-
Fields inherited from class org.eclipse.jetty.util.log.AbstractLogger
LEVEL_ALL, LEVEL_DEBUG, LEVEL_DEFAULT, LEVEL_INFO, LEVEL_OFF, LEVEL_WARN
-
-
Constructor Summary
Constructors Constructor Description StdErrLog()
Construct an anonymous StdErrLog (no name).StdErrLog(java.lang.String name)
Construct a named StdErrLog using theLog
defined propertiesStdErrLog(java.lang.String name, java.util.Properties props)
Construct a named Logger using the provided properties to configure logger.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
debug(java.lang.String msg, long arg)
Formats and logs at debug level.void
debug(java.lang.String msg, java.lang.Object... args)
Formats and logs at debug level.void
debug(java.lang.String msg, java.lang.Throwable thrown)
Logs the given message at debug level, with Throwable information.void
debug(java.lang.Throwable thrown)
Logs the given Throwable information at debug levelprivate void
escape(java.lang.StringBuilder builder, java.lang.String str)
private void
format(java.lang.StringBuilder builder, java.lang.String level, java.lang.String msg, java.lang.Object... inArgs)
private void
formatCause(java.lang.StringBuilder builder, java.lang.Throwable cause, java.lang.String indent)
private int
getConfiguredLevel()
int
getLevel()
static StdErrLog
getLogger(java.lang.Class<?> clazz)
Obtain a StdErrLog reference for the specified class, a convenience method used most often during testing to allow for control over a specific logger.static int
getLoggingLevel(java.util.Properties props, java.lang.String name)
java.lang.String
getName()
void
ignore(java.lang.Throwable ignored)
Ignore an exception.void
info(java.lang.String msg, java.lang.Object... args)
Formats and logs at info level.void
info(java.lang.String msg, java.lang.Throwable thrown)
Logs the given message at info level, with Throwable information.void
info(java.lang.Throwable thrown)
Logs the given Throwable information at info levelboolean
isDebugEnabled()
boolean
isHideStacks()
boolean
isPrintLongNames()
boolean
isSource()
Is the source of a log, loggedprotected Logger
newLogger(java.lang.String fullname)
Create a Child Logger of this Logger.private void
println(java.lang.StringBuilder builder)
void
setDebugEnabled(boolean enabled)
Legacy interface where a programmatic configuration of the logger level is done as a wholesale approach.void
setHideStacks(boolean hideStacks)
void
setLevel(int level)
Set the level for this logger.void
setPrintLongNames(boolean printLongNames)
void
setSource(boolean source)
Set if a log source is logged.void
setStdErrStream(java.io.PrintStream stream)
The alternate stream to use for STDERR.static void
setTagPad(int pad)
private void
tag(java.lang.StringBuilder builder, java.lang.String d, int ms, java.lang.String tag)
java.lang.String
toString()
void
warn(java.lang.String msg, java.lang.Object... args)
Formats and logs at warn level.void
warn(java.lang.String msg, java.lang.Throwable thrown)
Logs the given message at warn level, with Throwable information.void
warn(java.lang.Throwable thrown)
Logs the given Throwable information at warn level-
Methods inherited from class org.eclipse.jetty.util.log.AbstractLogger
condensePackageString, getLevelId, getLogger, getLoggingProperty, lookupLoggingLevel
-
-
-
-
Field Detail
-
EOL
private static final java.lang.String EOL
-
EMPTY_ARGS
private static final java.lang.Object[] EMPTY_ARGS
-
__tagpad
private static int __tagpad
-
_dateCache
private static DateCache _dateCache
-
__source
private static final boolean __source
-
__long
private static final boolean __long
-
__escape
private static final boolean __escape
-
_level
private int _level
-
_configuredLevel
private int _configuredLevel
-
_altStream
private java.io.PrintStream _altStream
-
_source
private boolean _source
-
_printLongNames
private boolean _printLongNames
-
_name
private final java.lang.String _name
-
_abbrevname
protected final java.lang.String _abbrevname
-
_hideStacks
private boolean _hideStacks
-
-
Constructor Detail
-
StdErrLog
public StdErrLog()
Construct an anonymous StdErrLog (no name).NOTE: Discouraged usage!
-
StdErrLog
public StdErrLog(java.lang.String name)
Construct a named StdErrLog using theLog
defined properties- Parameters:
name
- the name of the logger
-
StdErrLog
public StdErrLog(java.lang.String name, java.util.Properties props)
Construct a named Logger using the provided properties to configure logger.- Parameters:
name
- the name of the loggerprops
- the configuration properties
-
-
Method Detail
-
setTagPad
public static void setTagPad(int pad)
-
getLoggingLevel
public static int getLoggingLevel(java.util.Properties props, java.lang.String name)
-
getLogger
public static StdErrLog getLogger(java.lang.Class<?> clazz)
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.
- Parameters:
clazz
- the Class reference for the logger to use.- Returns:
- the StdErrLog logger
- Throws:
java.lang.RuntimeException
- if StdErrLog is not the active Logger implementation.
-
getName
public java.lang.String getName()
- Returns:
- the name of this logger
-
setPrintLongNames
public void setPrintLongNames(boolean printLongNames)
-
isPrintLongNames
public boolean isPrintLongNames()
-
isHideStacks
public boolean isHideStacks()
-
setHideStacks
public void setHideStacks(boolean hideStacks)
-
isSource
public boolean isSource()
Is the source of a log, logged- Returns:
- true if the class, method, file and line number of a log is logged.
-
setSource
public void setSource(boolean source)
Set if a log source is logged.- Parameters:
source
- true if the class, method, file and line number of a log is logged.
-
warn
public void warn(java.lang.String msg, java.lang.Object... args)
Description copied from interface:Logger
Formats and logs at warn level.- Parameters:
msg
- the formatting stringargs
- the optional arguments
-
warn
public void warn(java.lang.Throwable thrown)
Description copied from interface:Logger
Logs the given Throwable information at warn level- Parameters:
thrown
- the Throwable to log
-
warn
public void warn(java.lang.String msg, java.lang.Throwable thrown)
Description copied from interface:Logger
Logs the given message at warn level, with Throwable information.- Parameters:
msg
- the message to logthrown
- the Throwable to log
-
info
public void info(java.lang.String msg, java.lang.Object... args)
Description copied from interface:Logger
Formats and logs at info level.- Parameters:
msg
- the formatting stringargs
- the optional arguments
-
info
public void info(java.lang.Throwable thrown)
Description copied from interface:Logger
Logs the given Throwable information at info level- Parameters:
thrown
- the Throwable to log
-
info
public void info(java.lang.String msg, java.lang.Throwable thrown)
Description copied from interface:Logger
Logs the given message at info level, with Throwable information.- Parameters:
msg
- the message to logthrown
- the Throwable to log
-
isDebugEnabled
@ManagedAttribute("is debug enabled for root logger Log.LOG") public boolean isDebugEnabled()
- Returns:
- whether the debug level is enabled
-
setDebugEnabled
public void setDebugEnabled(boolean enabled)
Legacy interface where a programmatic configuration of the logger level is done as a wholesale approach.- Parameters:
enabled
- whether to enable the debug level
-
getConfiguredLevel
private int getConfiguredLevel()
-
getLevel
public int getLevel()
-
setLevel
public void setLevel(int level)
Set the level for this logger.Available values (
AbstractLogger.LEVEL_ALL
,AbstractLogger.LEVEL_DEBUG
,AbstractLogger.LEVEL_INFO
,AbstractLogger.LEVEL_WARN
)- Parameters:
level
- the level to set the logger to
-
setStdErrStream
public void setStdErrStream(java.io.PrintStream stream)
The alternate stream to use for STDERR.- Parameters:
stream
- the stream of choice, ornull
to useSystem.err
-
debug
public void debug(java.lang.String msg, java.lang.Object... args)
Description copied from interface:Logger
Formats and logs at debug level.- Parameters:
msg
- the formatting stringargs
- the optional arguments
-
debug
public void debug(java.lang.String msg, long arg)
Description copied from interface:Logger
Formats and logs at debug level. avoids autoboxing of integers- Specified by:
debug
in interfaceLogger
- Overrides:
debug
in classAbstractLogger
- Parameters:
msg
- the formatting stringarg
- long value
-
debug
public void debug(java.lang.Throwable thrown)
Description copied from interface:Logger
Logs the given Throwable information at debug level- Parameters:
thrown
- the Throwable to log
-
debug
public void debug(java.lang.String msg, java.lang.Throwable thrown)
Description copied from interface:Logger
Logs the given message at debug level, with Throwable information.- Parameters:
msg
- the message to logthrown
- the Throwable to log
-
println
private void println(java.lang.StringBuilder builder)
-
format
private void format(java.lang.StringBuilder builder, java.lang.String level, java.lang.String msg, java.lang.Object... inArgs)
-
formatCause
private void formatCause(java.lang.StringBuilder builder, java.lang.Throwable cause, java.lang.String indent)
-
escape
private void escape(java.lang.StringBuilder builder, java.lang.String str)
-
tag
private void tag(java.lang.StringBuilder builder, java.lang.String d, int ms, java.lang.String tag)
-
newLogger
protected Logger newLogger(java.lang.String fullname)
Create a Child Logger of this Logger.- Specified by:
newLogger
in classAbstractLogger
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
ignore
public void ignore(java.lang.Throwable ignored)
Description copied from interface:Logger
Ignore an exception.This should be used rather than an empty catch block.
- Parameters:
ignored
- the throwable to log as ignored
-
-