public final class LoggingHelper
extends java.lang.Object
Credits: https://blogs.oracle.com/nickstephen/entry/java_redirecting_system_out_and
Modifier and Type | Class and Description |
---|---|
static class |
LoggingHelper.LoggingOutputStream
An OutputStream that writes contents to a Logger upon each call to flush()
|
static class |
LoggingHelper.StdOutErrLevel |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_FORMAT |
static java.lang.String |
FORMAT_PROP_KEY |
Modifier and Type | Method and Description |
---|---|
static void |
addLoggingHandler(java.util.logging.Handler handler) |
static java.util.logging.FileHandler |
getFileHandler(java.lang.String processId,
java.lang.String loggingDir,
boolean append,
int limit,
int count)
Initialize a FileHandler to write to a set of files
with optional append.
|
static void |
loggerInit(java.util.logging.Level level,
boolean isRedirectStdOutErr)
Init java util logging with default format
|
static void |
loggerInit(java.util.logging.Level level,
boolean isRedirectStdOutErr,
java.lang.String format)
Init java util logging
|
protected static void |
setLoggingFormat(java.lang.String format) |
public static final java.lang.String FORMAT_PROP_KEY
public static final java.lang.String DEFAULT_FORMAT
public static void loggerInit(java.util.logging.Level level, boolean isRedirectStdOutErr) throws java.io.IOException
level
- the Level of message to logisRedirectStdOutErr
- whether we redirect std out&errjava.io.IOException
public static void loggerInit(java.util.logging.Level level, boolean isRedirectStdOutErr, java.lang.String format) throws java.io.IOException
level
- the Level of message to logisRedirectStdOutErr
- whether we redirect std out&errformat
- the format to logjava.io.IOException
protected static void setLoggingFormat(java.lang.String format)
public static void addLoggingHandler(java.util.logging.Handler handler)
public static java.util.logging.FileHandler getFileHandler(java.lang.String processId, java.lang.String loggingDir, boolean append, int limit, int count) throws java.io.IOException, java.lang.SecurityException
The FileHandler is configured based on LogManager properties (or their default values) except that the given pattern argument is used as the filename pattern, the file limit is set to the limit argument, and the file count is set to the given count argument, and the append mode is set to the given append argument.
The count must be at least 1.
limit
- the maximum number of bytes to write to any one filecount
- the number of files to useappend
- specifies append modejava.io.IOException
- if there are IO problems opening the files.java.lang.SecurityException
- if a security manager exists and if
the caller does not have LoggingPermission("control").java.lang.IllegalArgumentException
- if limit < 0
, or count < 1
.java.lang.IllegalArgumentException
- if pattern is an empty string