Package nl.colorize.util
Class LogHelper
java.lang.Object
nl.colorize.util.LogHelper
Helper methods for initializing and configuring
java.util.logging
loggers programmatically. A default logging configuration is automatically
applied to all logger in the nl.colorize
namespace.-
Method Summary
Modifier and TypeMethodDescriptionstatic Handler
createCallbackHandler
(Consumer<Throwable> callback) Creates a log handler that will invoke the specified callback function for every log message that contains an attachedThrowable
.static Formatter
Creates a log message formatter that uses a compact format with log records only taking up a single line.static ConsoleHandler
Creates a log handler that will log tostderr
.static FileHandler
createFileHandler
(File logfile) Creates a log handler that will log to the specified file using the platform's default character encoding.static FileHandler
createFileHandler
(File logfile, Charset encoding) Creates a log handler that will log to the specified file.static ConsoleHandler
Deprecated.static Handler
createStringHandler
(StringWriter stringWriter) Creates a log handler that will write log messages to the specifiedStringWriter
and uses a compact formatter.static Handler
createStringHandler
(StringWriter stringWriter, Formatter formatter) Creates a log handler that will write log messages to the specifiedStringWriter
.static Logger
Obtains the logger with the name of the specified class.static Logger
Obtains the logger with the specified name.static String
Returns the strack trace for the specified exception as a string.
-
Method Details
-
getLogger
Obtains the logger with the name of the specified class. The logger is returned with its existing, possibly inherited, configuration. -
getLogger
Obtains the logger with the specified name. The logger is returned with its existing, possibly inherited, configuration. -
createConsoleHandler
Creates a log handler that will log tostderr
. The handler will use the platform's default character encoding. -
createPlainConsoleHandler
Deprecated.UsecreateConsoleHandler()
in combination with aCompactFormatter
instead.Creates a log handler that will print messages tostderr
and will not apply any formatting to messages. -
createFileHandler
Creates a log handler that will log to the specified file using the platform's default character encoding.- Throws:
IllegalArgumentException
- if the file is not writeable.
-
createFileHandler
Creates a log handler that will log to the specified file.- Throws:
IllegalArgumentException
- if the file is not writeable.
-
createCallbackHandler
Creates a log handler that will invoke the specified callback function for every log message that contains an attachedThrowable
. The log level is initially set toSEVERE
. -
createStringHandler
Creates a log handler that will write log messages to the specifiedStringWriter
. -
createStringHandler
Creates a log handler that will write log messages to the specifiedStringWriter
and uses a compact formatter. -
createCompactFormatter
Creates a log message formatter that uses a compact format with log records only taking up a single line. This makes it easier to process log files in other tools, or scan them manually.Messages are logged using the default time zone for date and time. See
Platform.getDefaultTimeZone()
for more information. -
getStackTrace
Returns the strack trace for the specified exception as a string.When running on TeaVM, the "native" Java stack trace is not available, and this method will instead return the exception message.
-
createConsoleHandler()
in combination with aCompactFormatter
instead.