public class Log extends Object
Note: Instead of "just" logging exceptions, handle them with Exceptions.handle()
to generate sophisticated error messages and to permit other parts of the framework to intercept error
handling.
In contrast to other approaches, it is not recommended to create a logger per class, but rather one per
framework or sub system. It should have a concise name, all lowercase without any dots. The log level of each
logger is read from the configuration using logging.[NAME]
. It may be set to one of:
Internally uses log4j to perform all logging operations. Still it is recommended to only log through this facade and not to rely on any log4j specific behaviour.
Modifier and Type | Method and Description |
---|---|
static org.apache.log4j.Level |
convertJuliLevel(Level juliLevel)
Converts a given java.util.logging.Level to a log4j level.
|
static Level |
convertLog4jLevel(org.apache.log4j.Level log4jLevel)
Converts a given log4j to a java.util.logging.Level level.
|
void |
DEBUG_INFO(Object msg)
Used to log the given message msg at INFO level if debug mode is enabled
(
Sirius.isDev() ). |
void |
FINE(Object msg)
Logs the given message at the FINE level
The given object is converted to a string if necessary.
|
void |
FINE(String msg,
Object... params)
Formats the given message at the FINE level using the supplied parameters.
|
static Log |
get(String name)
Generates a new logger with the given name
The given name should be short and simple.
|
static List<Log> |
getAllLoggers()
Returns a list of all known loggers.
|
String |
getName()
Returns the name of this logger
|
void |
INFO(Object msg)
Logs the given message at INFO level
The given object is converted to a string if necessary.
|
void |
INFO(String msg,
Object... params)
Formats the given message at the INFO level using the supplied parameters.
|
boolean |
isFINE()
Determines if FINE message will be logged.
|
static void |
setLevel(String logger,
org.apache.log4j.Level level)
Helper method the change the log-level for a given logger.
|
void |
SEVERE(Object msg)
Logs the given message at the SEVERE or ERROR level
The given object is converted to a string if necessary.
|
void |
WARN(Object msg)
Logs the given message at the WARN level
The given object is converted to a string if necessary.
|
void |
WARN(String msg,
Object... params)
Formats the given message at the WARN level using the supplied parameters.
|
public static Log get(String name)
The given name should be short and simple. It is not recommended to create a logger per class but one for each framework or subsystem.
name
- the name of the logger. This should be a simple name, completely lowercase, without any dotspublic static List<Log> getAllLoggers()
public static void setLevel(String logger, org.apache.log4j.Level level)
By default the system configuration is used to set the leg level (logging.[name]=LEVEL). Also the "logger" command in the console can be used to change the log level at runtime.
logger
- the name of the logger to changelevel
- the desired log levelpublic static org.apache.log4j.Level convertJuliLevel(Level juliLevel)
juliLevel
- the java.util.logging levelpublic static Level convertLog4jLevel(org.apache.log4j.Level log4jLevel)
log4jLevel
- the log4j levelpublic void INFO(Object msg)
The given object is converted to a string if necessary. The INFO level should be used for informative messages to the system operator which occur at a low rate
msg
- the message to be loggedpublic void DEBUG_INFO(Object msg)
Sirius.isDev()
). Otherwise the message will be logged as FINE.msg
- the message to logpublic void INFO(String msg, Object... params)
The INFO level should be used for informative messages to the system operator which occur at a low rate
msg
- the message containing placeholders as understood by Strings.apply(String, Object...)
params
- the parameters used to format the resulting log messagepublic void FINE(Object msg)
The given object is converted to a string if necessary. The FINE level can be used for in depth debug or trace messages used when developing a system. Sill the rate should be kept bearable to enable this level in production systems to narrow down errors.
msg
- the message to be loggedpublic void FINE(String msg, Object... params)
The FINE level can be used for in depth debug or trace messages used when developing a system. Sill the rate should be kept bearable to enable this level in production systems to narrow down errors.
msg
- the message containing placeholders as understood by Strings.apply(String, Object...)
params
- the parameters used to format the resulting log messagepublic void WARN(Object msg)
The given object is converted to a string if necessary. The WARN level can be used to signal unexpected situations which do not (yet) result in an error or problem.
msg
- the message to be loggedpublic void WARN(String msg, Object... params)
The WARN level can be used to signal unexpected situations which do not (yet) result in an error or problem.
msg
- the message containing placeholders as understood by Strings.apply(String, Object...)
params
- the parameters used to format the resulting log messagepublic void SEVERE(Object msg)
The given object is converted to a string if necessary. The ERROR level can be used to signal problems or error
which occurred in the system. It is recommended to handle exceptions using Exceptions
- which will
eventually also call this method, but provides sophisticated error handling.
msg
- the message to be loggedpublic boolean isFINE()
This can be used to decide whether "expensive" log messages should be constructed at all. Using
FINE(String, Object...)
doesn't require this check since the message is only formatted if it will be
logged. However, if the computation of one of the parameters is complex, one might sill want to surround the
log message by an appropriate if statement calling this method.
public String getName()
get(String)
.Copyright © 2018. All rights reserved.