@ThreadSafe
public class Logger
extends Object
implements Externalizable, Thread.UncaughtExceptionHandler
Support is provided for the messages resources and formatting classes. To minimize overhead, the resource access and text formatting is done just in time.
This class is serializable, but the serialization process only propagates the logger identification (name).
The current implementation is a thin wrapper over Log4J.
| Modifier and Type | Class and Description |
|---|---|
static class |
Logger.LogLevel
Log Level.
|
static interface |
Logger.LogListener
Log listener.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
ID_KEY
Diagnostic Context ID key.
|
static String |
LOG_ID_PROPERTY
Log ID property.
|
static String |
MIDNIGHT_LOGGER_NAME
Midnight logger name.
|
| Modifier | Constructor and Description |
|---|---|
|
Logger()
Constructs an instance.
|
protected |
Logger(Class<?> ownerClass)
Constructs an instance.
|
protected |
Logger(Logger log4jLogger)
Constructs an instance.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
addListener(Logger.LogListener listener)
Adds a listener for this logger.
|
static Optional<String> |
currentLogID()
Returns the current log ID.
|
void |
debug(Message message)
Logs a debug message.
|
void |
debug(Messages.Entry entry,
Object... params)
Logs a debug message.
|
void |
debug(String format,
Object... params)
Deprecated.
For temporary use.
|
void |
debug(Supplier<Message> messageSupplier)
Logs a debug message.
|
void |
debug(Throwable cause,
Messages.Entry entry,
Object... params)
Logs a debug message.
|
void |
debug(Throwable cause,
String format,
Object... params)
Deprecated.
For temporary use.
|
protected void |
doLog(Logger.LogLevel logLevel,
Message message)
Logs a message.
|
void |
error(Message message)
Logs an error message.
|
void |
error(Messages.Entry entry,
Object... params)
Logs an error message.
|
void |
error(String format,
Object... params)
Deprecated.
For temporary use.
|
void |
error(Throwable cause,
Messages.Entry entry,
Object... params)
Logs an error message.
|
void |
error(Throwable cause,
String format,
Object... params)
Deprecated.
For temporary use.
|
void |
fatal(Message message)
Logs a fatal message.
|
void |
fatal(Messages.Entry entry,
Object... params)
Logs a fatal message.
|
void |
fatal(String format,
Object... params)
Deprecated.
For temporary use.
|
void |
fatal(Throwable cause,
Messages.Entry entry,
Object... params)
Logs a fatal message.
|
void |
fatal(Throwable cause,
String format,
Object... params)
Deprecated.
For temporary use.
|
static Logger |
getInstance(Class<?> ownerClass)
Gets a logger instance.
|
static Logger |
getInstance(Logger log4jLogger)
Gets a logger instance.
|
static Logger |
getInstance(String name)
Gets a logger instance.
|
protected Level |
getLog4jLevel()
Gets the log4j Level.
|
protected Logger |
getLog4jLogger()
Gets the log4j Logger.
|
Logger.LogLevel |
getLogLevel()
Gets the log level.
|
static Logger |
getMidnightLogger()
Gets the MIDNIGHT logger.
|
String |
getName()
Gets this logger's name.
|
PrintWriter |
getPrintWriter(Logger.LogLevel logLevel)
Gets a PrintWriter
All messages sent to the PrintWriter will be processed according to
the log level supplied here.
|
boolean |
hasLogged(Logger.LogLevel logLevel)
Asks if this has logged at least at the specified level.
|
void |
info(Message message)
Logs an info message.
|
void |
info(Messages.Entry entry,
Object... params)
Logs an info message.
|
void |
info(String format,
Object... params)
Deprecated.
For temporary use.
|
void |
info(Supplier<Message> messageSupplier)
Logs an info message.
|
void |
info(Throwable cause,
Messages.Entry entry,
Object... params)
Logs an info message.
|
void |
info(Throwable cause,
String format,
Object... params)
Deprecated.
For temporary use.
|
boolean |
isDebugEnabled()
Asks if the debug level is enabled.
|
boolean |
isEnabledFor(Logger.LogLevel logLevel)
Asks if a log level is enabled.
|
boolean |
isInfoEnabled()
Asks if the info level is enabled.
|
static boolean |
isShutDown()
Asks if logging is shut down.
|
boolean |
isTraceEnabled()
Asks if the trace level is enabled.
|
void |
log(Logger.LogLevel logLevel,
Message message)
Logs a message.
|
void |
log(Logger.LogLevel logLevel,
Messages.Entry entry,
Object... params)
Logs a message.
|
void |
log(Logger.LogLevel logLevel,
String format,
Object... params)
Logs a message.
|
void |
log(Logger.LogLevel logLevel,
Supplier<Message> messageSupplier)
Logs a debug message.
|
void |
log(Logger.LogLevel logLevel,
Throwable cause,
Messages.Entry entry,
Object... params)
Logs a message.
|
void |
log(Logger.LogLevel logLevel,
Throwable cause,
String format,
Object... params)
Logs a message.
|
static void |
logBackEnd()
Logs back end informations.
|
void |
readExternal(ObjectInput input) |
static boolean |
removeListener(Logger.LogListener listener)
Removes a listener for this logger.
|
void |
reset()
Resets the maximum level actually logged with this logger.
|
static void |
restoreLogID(Optional<String> logID)
Restores the log ID.
|
static void |
setLogID()
Sets the log ID to its default value.
|
static void |
setLogID(Optional<String> logID)
Sets the log ID.
|
static void |
shutDown()
Shuts down logging.
|
static void |
startUp(boolean manualShutdown)
Starts up logging.
|
void |
trace(Message message)
Logs a trace message.
|
void |
trace(Messages.Entry entry,
Object... params)
Logs a trace message.
|
void |
trace(String format,
Object... params)
Deprecated.
For temporary use.
|
void |
trace(Supplier<Message> messageSupplier)
Logs a trace message.
|
void |
trace(Throwable cause,
Messages.Entry entry,
Object... params)
Logs a trace message.
|
void |
trace(Throwable cause,
String format,
Object... params)
Deprecated.
For temporary use.
|
void |
uncaughtException(Thread thread,
Throwable throwable) |
void |
warn(Message message)
Logs a warning message.
|
void |
warn(Messages.Entry entry,
Object... params)
Logs a warning message.
|
void |
warn(String format,
Object... params)
Deprecated.
For temporary use.
|
void |
warn(Throwable cause,
Messages.Entry entry,
Object... params)
Logs a warning message.
|
void |
warn(Throwable cause,
String format,
Object... params)
Deprecated.
For temporary use.
|
void |
writeExternal(ObjectOutput output) |
public static final String ID_KEY
public static final String LOG_ID_PROPERTY
public static final String MIDNIGHT_LOGGER_NAME
public Logger()
This is needed for an Externalizable implementation.
protected Logger(@Nonnull
Class<?> ownerClass)
ownerClass - The owner class.protected Logger(@Nonnull
Logger log4jLogger)
log4jLogger - The 'org.apache.logging.log4j' Logger.@CheckReturnValue
public static boolean addListener(@Nonnull
Logger.LogListener listener)
listener - The listener.@Nonnull @CheckReturnValue public static Optional<String> currentLogID()
@Nonnull @CheckReturnValue public static Logger getInstance(@Nonnull Class<?> ownerClass)
ownerClass - The class of the logger's owner.@Nonnull @CheckReturnValue public static Logger getInstance(@Nonnull Logger log4jLogger)
This is used by scripts to supply their Log4j logger in calls to RVPF.
log4jLogger - A log4j logger.@Nonnull @CheckReturnValue public static Logger getInstance(@Nonnull String name)
name - The logger's name.@Nonnull @CheckReturnValue public static Logger getMidnightLogger()
@CheckReturnValue public static boolean isShutDown()
public static void logBackEnd()
@CheckReturnValue
public static boolean removeListener(@Nonnull
Logger.LogListener listener)
listener - The listener.public static void restoreLogID(@Nonnull
Optional<String> logID)
If the log ID is empty, any previous value is removed.
logID - The log ID.public static void setLogID()
public static void setLogID(@Nonnull
Optional<String> logID)
If the log ID is empty, a new value is generated.
logID - The log ID.public static void shutDown()
public static void startUp(boolean manualShutdown)
manualShutdown - True if shutDown() will be called.public final void debug(@Nonnull
Message message)
message - The message.public final void debug(@Nonnull
Supplier<Message> messageSupplier)
messageSupplier - A message supplier.public final void debug(@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
entry - The messages entry.params - The message parameters.@Deprecated
public final void debug(@Nonnull
String format,
@Nonnull
Object... params)
format - The message format.params - The message parameters.public final void debug(@Nonnull
Throwable cause,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
cause - The message cause.entry - The messages entry.params - The message parameters.@Deprecated
public final void debug(@Nonnull
Throwable cause,
@Nonnull
String format,
@Nonnull
Object... params)
cause - The message cause.format - The message format.params - The message parameters.public final void error(@Nonnull
Message message)
message - The message.public final void error(@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
entry - The messages entry.params - The message parameters.@Deprecated
public final void error(@Nonnull
String format,
@Nonnull
Object... params)
format - The message format.params - The message parameters.public final void error(@Nonnull
Throwable cause,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
cause - The message cause.entry - The messages entry.params - The message parameters.@Deprecated
public final void error(@Nonnull
Throwable cause,
@Nonnull
String format,
@Nonnull
Object... params)
cause - The message cause.format - The message format.params - The message parameters.public final void fatal(@Nonnull
Message message)
message - The message.public final void fatal(@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
entry - The messages entry.params - The message parameters.@Deprecated
public final void fatal(@Nonnull
String format,
@Nonnull
Object... params)
format - The message format.params - The message parameters.public final void fatal(@Nonnull
Throwable cause,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
cause - The message cause.entry - The messages entry.params - The message parameters.@Deprecated
public final void fatal(@Nonnull
Throwable cause,
@Nonnull
String format,
@Nonnull
Object... params)
cause - The message cause.format - The message format.params - The message parameters.@Nonnull @CheckReturnValue public final Logger.LogLevel getLogLevel()
@Nonnull @CheckReturnValue public final String getName()
@Nonnull
@CheckReturnValue
public final PrintWriter getPrintWriter(@Nonnull
Logger.LogLevel logLevel)
All messages sent to the PrintWriter will be processed according to the log level supplied here.
logLevel - The log level.@CheckReturnValue
public final boolean hasLogged(@Nonnull
Logger.LogLevel logLevel)
logLevel - A LogLevel.reset()public final void info(@Nonnull
Message message)
message - The message.public final void info(@Nonnull
Supplier<Message> messageSupplier)
messageSupplier - A message supplier.public final void info(@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
entry - The messages entry.params - The message parameters.@Deprecated
public final void info(@Nonnull
String format,
@Nonnull
Object... params)
format - The message format.params - The message parameters.public final void info(@Nonnull
Throwable cause,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
cause - The message cause.entry - The messages entry.params - The message parameters.@Deprecated
public final void info(@Nonnull
Throwable cause,
@Nonnull
String format,
@Nonnull
Object... params)
cause - The message cause.format - The message format.params - The message parameters.@CheckReturnValue public final boolean isDebugEnabled()
@CheckReturnValue public final boolean isEnabledFor(Logger.LogLevel logLevel)
logLevel - The log level.@CheckReturnValue public final boolean isInfoEnabled()
@CheckReturnValue public final boolean isTraceEnabled()
public final void log(@Nonnull
Logger.LogLevel logLevel,
@Nonnull
Message message)
logLevel - The log level.message - The message.public final void log(@Nonnull
Logger.LogLevel logLevel,
@Nonnull
Supplier<Message> messageSupplier)
logLevel - The log level.messageSupplier - A message supplier.public final void log(@Nonnull
Logger.LogLevel logLevel,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
logLevel - The log level.entry - The messages entry.params - The message parameters.public final void log(@Nonnull
Logger.LogLevel logLevel,
@Nonnull
String format,
@Nonnull
Object... params)
logLevel - The log level.format - The message format.params - The message parameters.public final void log(@Nonnull
Logger.LogLevel logLevel,
@Nonnull
Throwable cause,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
logLevel - The log level.cause - The message cause.entry - The messages entry.params - The message parameters.public final void log(@Nonnull
Logger.LogLevel logLevel,
@Nonnull
Throwable cause,
@Nonnull
String format,
@Nonnull
Object... params)
logLevel - The log level.cause - The message cause.format - The message format.params - The message parameters.public final void readExternal(@Nonnull
ObjectInput input)
throws IOException
readExternal in interface ExternalizableIOExceptionpublic final void reset()
public final void trace(@Nonnull
Message message)
message - The message.public final void trace(@Nonnull
Supplier<Message> messageSupplier)
messageSupplier - A message supplier.public final void trace(@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
entry - The messages entry.params - The message parameters.@Deprecated
public final void trace(@Nonnull
String format,
@Nonnull
Object... params)
format - The message format.params - The message parameters.public final void trace(@Nonnull
Throwable cause,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
cause - The message cause.entry - The messages entry.params - The message parameters.@Deprecated
public final void trace(@Nonnull
Throwable cause,
@Nonnull
String format,
@Nonnull
Object... params)
cause - The message cause.format - The message format.params - The message parameters.public final void uncaughtException(@Nonnull
Thread thread,
@Nonnull
Throwable throwable)
uncaughtException in interface Thread.UncaughtExceptionHandlerpublic final void warn(@Nonnull
Message message)
message - The message.public final void warn(@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
entry - The messages entry.params - The message parameters.@Deprecated
public final void warn(@Nonnull
String format,
@Nonnull
Object... params)
format - The message format.params - The message parameters.public final void warn(@Nonnull
Throwable cause,
@Nonnull
Messages.Entry entry,
@Nonnull
Object... params)
cause - The message cause.entry - The messages entry.params - The message parameters.@Deprecated
public final void warn(@Nonnull
Throwable cause,
@Nonnull
String format,
@Nonnull
Object... params)
cause - The message cause.format - The message format.params - The message parameters.public final void writeExternal(@Nonnull
ObjectOutput output)
throws IOException
writeExternal in interface ExternalizableIOExceptionprotected void doLog(@Nonnull
Logger.LogLevel logLevel,
@Nonnull
Message message)
logLevel - The log level.message - The message.@Nonnull @CheckReturnValue protected final Level getLog4jLevel()
@Nonnull @CheckReturnValue protected final Logger getLog4jLogger()
Copyright © 2003-2019 Serge Brisson. All Rights Reserved.