public class PrintStreamLogger extends AbstractLogger
The initial log level is ERROR. It can be changed via the property 'logging.level' (e.g. logging.level=WARNING).
Modifier and Type | Field and Description |
---|---|
static int |
LEVEL_DEBUG
This log level specifies that all messages will be logged
|
static int |
LEVEL_ERROR
This log level specifies that only error messages will be logged
|
static int |
LEVEL_INFO
This log level specifies that only error, warning and info messages will
be logged
|
static int |
LEVEL_NONE
This log level specifies that no message at all will be logged
|
static int |
LEVEL_WARN
This log level specifies that only error and warning messages will be
logged
|
static java.lang.String |
PROP_LOG_LEVEL
The property to set the log level.
|
static java.lang.String |
PROP_LOGGER_NAME
The property to set the the name of the logger.
|
static java.lang.String |
PROP_OUTPUT_FILE
The property that specifies a filename to redirect the log output
|
ANONYMOUS_LOGGER_NAME, LL_DEBUG, LL_ERROR, LL_INFO, LL_NONE, LL_WARNING
Constructor and Description |
---|
PrintStreamLogger()
Initialize the new instance with default values.
|
PrintStreamLogger(java.lang.String loggerName)
Initialize the new instance with a logger name.
|
Modifier and Type | Method and Description |
---|---|
static PrintStreamLogger |
create(java.lang.String loggerName)
Create a new instance with a logger name.
|
protected java.lang.String |
getLevelIndicator(int level) |
int |
getLogLevel()
Returns the current log level
|
protected LogMessageOutputTarget |
getOutputTarget() |
void |
initialize(java.util.Properties properties)
Initialize the logger from the given properties settings.
|
protected boolean |
initLogLevel(java.lang.String level) |
protected void |
initPrintStream(java.lang.String filename) |
boolean |
isLoggingDebugs()
Returns true, if debug messages will be written to the output device(s).
|
boolean |
isLoggingErrors()
Returns true, if errors will be written to the output device(s).
|
boolean |
isLoggingInfos()
Returns true, if info messages will be written to the output device(s).
|
boolean |
isLoggingWarnings()
Returns true, if warnings will be written to the output device(s).
|
void |
logDebug(java.lang.String message,
java.lang.Object... params)
If the logging level is DEBUG the given message will be written to
the log output device(s).
|
void |
logError(java.lang.String message,
java.lang.Object... params)
If the logging level is DEBUG, INFO, WARNING or ERROR the given message
will be written to the log output device(s).
|
void |
logError(java.lang.String message,
java.lang.Throwable exception)
If the logging level is DEBUG, INFO, WARNING or ERROR the given message
and the exception will be written to the log output device(s).
|
void |
logException(java.lang.Throwable ex)
Writes the given exception to the log output device(s).
|
void |
logInfo(java.lang.String message,
java.lang.Object... params)
If the logging level is INFO or DEBUG the given message will be
written to the log output device(s).
|
void |
logWarning(java.lang.String message,
java.lang.Object... params)
If the logging level is DEBUG, INFO or WARNING the given message will
be written to the log output device(s).
|
void |
logWarning(java.lang.String message,
java.lang.Throwable exception)
If the logging level is DEBUG, INFO or WARNING the given message
and the exception will be written to the log output device(s).
|
protected void |
print(int level,
java.lang.String message,
java.lang.Object... params) |
protected void |
print(java.lang.String text) |
protected void |
printException(java.lang.Throwable ex) |
protected void |
println() |
protected void |
println(int level,
java.lang.String text,
java.lang.Object... params) |
protected void |
printLoggerNameIfSet() |
void |
setLogLevel(int newLevel)
Set the current log level of this logger.
|
boolean |
setLogLevel(java.lang.String logLevel)
Changes the log level to the specified level.
|
protected void |
setOutputTarget(LogMessageOutputTarget outputTarget) |
protected boolean |
useLevelIndicators() |
getLoggerName, getName, isNullOrBlank, isNullOrEmpty, replacePlaceholders, setLoggerName
public static final int LEVEL_NONE
public static final int LEVEL_ERROR
public static final int LEVEL_WARN
public static final int LEVEL_INFO
public static final int LEVEL_DEBUG
public static final java.lang.String PROP_OUTPUT_FILE
"logging.printstream.file"
public static final java.lang.String PROP_LOG_LEVEL
"logging.level"
public static final java.lang.String PROP_LOGGER_NAME
"logging.logger.name"
public PrintStreamLogger()
public PrintStreamLogger(java.lang.String loggerName)
public static PrintStreamLogger create(java.lang.String loggerName)
public int getLogLevel()
public void setLogLevel(int newLevel)
newLevel
- The new log level (i.e. one of the LEVEL_ constants of this class)public void initialize(java.util.Properties properties)
public void logException(java.lang.Throwable ex)
public void logDebug(java.lang.String message, java.lang.Object... params)
message
- The message to log. It may contain placeholders like {0}, {1} etc.params
- Optional parameters to be used for replacing placeholders in the message text.public void logInfo(java.lang.String message, java.lang.Object... params)
message
- The message to log. It may contain placeholders like {0}, {1} etc.params
- Optional parameters to be used for replacing placeholders in the message text.public void logWarning(java.lang.String message, java.lang.Object... params)
message
- The message to log. It may contain placeholders like {0}, {1} etc.params
- Optional parameters to be used for replacing placeholders in the message text.public void logError(java.lang.String message, java.lang.Object... params)
message
- The message to log. It may contain placeholders like {0}, {1} etc.params
- Optional parameters to be used for replacing placeholders in the message text.public void logWarning(java.lang.String message, java.lang.Throwable exception)
public void logError(java.lang.String message, java.lang.Throwable exception)
public boolean isLoggingDebugs()
public boolean isLoggingInfos()
public boolean isLoggingWarnings()
public boolean isLoggingErrors()
public boolean setLogLevel(java.lang.String logLevel)
logLevel
- One of the LL_ constants defined in this interface (e.g. Logger.LL_ERROR
).protected void print(java.lang.String text)
protected void print(int level, java.lang.String message, java.lang.Object... params)
protected void println(int level, java.lang.String text, java.lang.Object... params)
protected void println()
protected void printLoggerNameIfSet()
protected void printException(java.lang.Throwable ex)
protected java.lang.String getLevelIndicator(int level)
protected boolean useLevelIndicators()
protected void initPrintStream(java.lang.String filename)
protected boolean initLogLevel(java.lang.String level)
protected LogMessageOutputTarget getOutputTarget()
protected void setOutputTarget(LogMessageOutputTarget outputTarget)