public final class Logger
extends org.macroing.cit.messaging.Messaging
Messaging extension for logging.
To demonstrate some of its use, consider the following example:
Logger logger = Logger.newInstance();
logger.getMessageChannel().addMessageChannelObserver((messageChannel, message) -> System.out.printf("%s%n", message));
logger.start();
logger.info("Hello, World!");
The above example demonstrates the fact that a Logger is nothing more than an empty shell by default. But it's flexible and allows you to configure it in many different ways. However, most of the time, you're
just interested in getting that Logger, so you can log whatever it is that you want to log. You don't want to spend a lot of time configuring it every now and then. It's good, then, that we've taken care of that
for you.
The methods getInstance(), getInstance(Class<?>) and getInstance(String) will delegate the responsibility of configuring to the current LoggerConfigurator. But only the first time, when
they're created.
| Modifier and Type | Method and Description |
|---|---|
void |
debug(java.lang.String message)
Call this method to log
message using Level.DEBUG. |
void |
debug(java.lang.String message,
java.lang.Throwable cause)
Call this method to log
message using Level.DEBUG. |
void |
debugf(java.lang.String format,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.DEBUG. |
void |
debugf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.DEBUG. |
void |
error(java.lang.String message)
Call this method to log
message using Level.ERROR. |
void |
error(java.lang.String message,
java.lang.Throwable cause)
Call this method to log
message using Level.ERROR. |
void |
errorf(java.lang.String format,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.ERROR. |
void |
errorf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.ERROR. |
void |
fatal(java.lang.String message)
Call this method to log
message using Level.FATAL. |
void |
fatal(java.lang.String message,
java.lang.Throwable cause)
Call this method to log
message using Level.FATAL. |
void |
fatalf(java.lang.String format,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.FATAL. |
void |
fatalf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.FATAL. |
static Logger |
getInstance()
Returns the default
Logger instance, with a key of "". |
static Logger |
getInstance(java.lang.Class<?> clazz)
Returns a
Logger instance given a key of clazz.getName(). |
static Logger |
getInstance(java.lang.String key)
Returns a
Logger instance given a key of key. |
static java.util.Collection<Logger> |
getLoggers()
Returns a
Collection with all Loggers currently in use. |
org.macroing.cit.messaging.MessageChannel |
getMessageChannel()
Returns the underlying
MessageChannel. |
void |
info(java.lang.String message)
Call this method to log
message using Level.INFO. |
void |
info(java.lang.String message,
java.lang.Throwable cause)
Call this method to log
message using Level.INFO. |
void |
infof(java.lang.String format,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.INFO. |
void |
infof(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.INFO. |
void |
log(java.lang.String message,
Level level)
Call this method to log
message using level. |
void |
log(java.lang.String message,
Level level,
java.lang.Throwable cause)
Call this method to log
message using level. |
void |
logf(java.lang.String format,
Level level,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using level. |
void |
logf(java.lang.String format,
Level level,
java.lang.Throwable cause,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using level. |
static Logger |
newInstance()
Returns a new empty
Logger instance. |
protected void |
onStart()
Overridden to handle start logic.
|
protected void |
onStop()
Overridden to handle stop logic.
|
void |
reset()
Resets this
Logger to its initial empty state. |
void |
warning(java.lang.String message)
Call this method to log
message using Level.WARNING. |
void |
warning(java.lang.String message,
java.lang.Throwable cause)
Call this method to log
message using Level.WARNING. |
void |
warningf(java.lang.String format,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.WARNING. |
void |
warningf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
Call this method to log
String.format(format, objects) using Level.WARNING. |
public org.macroing.cit.messaging.MessageChannel getMessageChannel()
MessageChannel.MessageChannelpublic void debug(java.lang.String message)
message using Level.DEBUG.
If message is null, a NullPointerException will be thrown.
message - the message to logjava.lang.NullPointerException - thrown if, and only if, message is nullpublic void debug(java.lang.String message,
java.lang.Throwable cause)
message using Level.DEBUG.
If either message or cause are null, a NullPointerException will be thrown.
message - the message to logcause - the causejava.lang.NullPointerException - thrown if, and only if, either message or cause are nullpublic void debugf(java.lang.String format,
java.lang.Object... objects)
String.format(format, objects) using Level.DEBUG.
If either format or objects are null, a NullPointerException will be thrown.
format - the format of the message to logobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format or objects are nullpublic void debugf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
String.format(format, objects) using Level.DEBUG.
If either format, cause or objects are null, a NullPointerException will be thrown.
format - the format of the message to logcause - the causeobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format, cause or objects are nullpublic void error(java.lang.String message)
message using Level.ERROR.
If message is null, a NullPointerException will be thrown.
message - the message to logjava.lang.NullPointerException - thrown if, and only if, message is nullpublic void error(java.lang.String message,
java.lang.Throwable cause)
message using Level.ERROR.
If either message or cause are null, a NullPointerException will be thrown.
message - the message to logcause - the causejava.lang.NullPointerException - thrown if, and only if, either message or cause are nullpublic void errorf(java.lang.String format,
java.lang.Object... objects)
String.format(format, objects) using Level.ERROR.
If either format or objects are null, a NullPointerException will be thrown.
format - the format of the message to logobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format or objects are nullpublic void errorf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
String.format(format, objects) using Level.ERROR.
If either format, cause or objects are null, a NullPointerException will be thrown.
format - the format of the message to logcause - the causeobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format, cause or objects are nullpublic void fatal(java.lang.String message)
message using Level.FATAL.
If message is null, a NullPointerException will be thrown.
message - the message to logjava.lang.NullPointerException - thrown if, and only if, message is nullpublic void fatal(java.lang.String message,
java.lang.Throwable cause)
message using Level.FATAL.
If either message or cause are null, a NullPointerException will be thrown.
message - the message to logcause - the causejava.lang.NullPointerException - thrown if, and only if, either message or cause are nullpublic void fatalf(java.lang.String format,
java.lang.Object... objects)
String.format(format, objects) using Level.FATAL.
If either format or objects are null, a NullPointerException will be thrown.
format - the format of the message to logobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format or objects are nullpublic void fatalf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
String.format(format, objects) using Level.FATAL.
If either format, cause or objects are null, a NullPointerException will be thrown.
format - the format of the message to logcause - the causeobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format, cause or objects are nullpublic void info(java.lang.String message)
message using Level.INFO.
If message is null, a NullPointerException will be thrown.
message - the message to logjava.lang.NullPointerException - thrown if, and only if, message is nullpublic void info(java.lang.String message,
java.lang.Throwable cause)
message using Level.INFO.
If either message or cause are null, a NullPointerException will be thrown.
message - the message to logcause - the causejava.lang.NullPointerException - thrown if, and only if, either message or cause are nullpublic void infof(java.lang.String format,
java.lang.Object... objects)
String.format(format, objects) using Level.INFO.
If either format or objects are null, a NullPointerException will be thrown.
format - the format of the message to logobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format or objects are nullpublic void infof(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
String.format(format, objects) using Level.INFO.
If either format, cause or objects are null, a NullPointerException will be thrown.
format - the format of the message to logcause - the causeobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format, cause or objects are nullprotected void onStart()
onStart in class org.macroing.cit.messaging.Messagingprotected void onStop()
onStop in class org.macroing.cit.messaging.Messagingpublic void log(java.lang.String message,
Level level)
message using level.
If either message or level are null, a NullPointerException will be thrown.
message - the message to loglevel - the Level to log withjava.lang.NullPointerException - thrown if, and only if, either message or level are nullpublic void log(java.lang.String message,
Level level,
java.lang.Throwable cause)
message using level.
If either message, level or cause are null, a NullPointerException will be thrown.
message - the message to loglevel - the Level to log withcause - the causejava.lang.NullPointerException - thrown if, and only if, either message, level or cause are nullpublic void logf(java.lang.String format,
Level level,
java.lang.Object... objects)
String.format(format, objects) using level.
If either format, level or objects are null, a NullPointerException will be thrown.
format - the format of the message to loglevel - the Level to log withobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format, level or objects are nullpublic void logf(java.lang.String format,
Level level,
java.lang.Throwable cause,
java.lang.Object... objects)
String.format(format, objects) using level.
If either format, level, cause or objects are null, a NullPointerException will be thrown.
format - the format of the message to loglevel - the Level to log withcause - the causeobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format, level, cause or objects are nullpublic void reset()
Logger to its initial empty state.
If you call this method, you may have to call LoggerConfigurator.configure(logger)
public void warning(java.lang.String message)
message using Level.WARNING.
If message is null, a NullPointerException will be thrown.
message - the message to logjava.lang.NullPointerException - thrown if, and only if, message is nullpublic void warning(java.lang.String message,
java.lang.Throwable cause)
message using Level.WARNING.
If either message or cause are null, a NullPointerException will be thrown.
message - the message to logcause - the causejava.lang.NullPointerException - thrown if, and only if, either message or cause are nullpublic void warningf(java.lang.String format,
java.lang.Object... objects)
String.format(format, objects) using Level.WARNING.
If either format or objects are null, a NullPointerException will be thrown.
format - the format of the message to logobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format or objects are nullpublic void warningf(java.lang.String format,
java.lang.Throwable cause,
java.lang.Object... objects)
String.format(format, objects) using Level.WARNING.
If either format, cause or objects are null, a NullPointerException will be thrown.
format - the format of the message to logcause - the causeobjects - an array of Objects to supply to the String.format(String, Object...) methodjava.lang.NullPointerException - thrown if, and only if, either format, cause or objects are nullpublic static java.util.Collection<Logger> getLoggers()
Collection with all Loggers currently in use.Collection with all Loggers currently in usepublic static Logger getInstance()
Logger instance, with a key of "".
If no Logger with a key of "" did exist prior to this method call, as per the contract of the method getInstance(String), it will be created and configured by the current LoggerConfigurator. In any other case, it
will simply just be returned.
Logger instance, with a key of ""public static Logger getInstance(java.lang.Class<?> clazz)
Logger instance given a key of clazz.getName().
If clazz is null, a NullPointerException will be thrown.
If no Logger with a key of clazz.getName() did exist prior to this method call, it will be created and configured by the current LoggerConfigurator. In any other case, it will simply just be
returned.
clazz - the Class whose name will be the key for the Logger instanceLogger instance given its key clazz.getName()java.lang.NullPointerException - thrown if, and only if, clazz is nullpublic static Logger getInstance(java.lang.String key)
Logger instance given a key of key.
If key is null, a NullPointerException will be thrown.
If no Logger with a key of key did exist prior to this method call, it will be created and configured by the current LoggerConfigurator. In any other case, it will simply just be returned.
key - the key for the Logger instanceLogger instance given its key keyjava.lang.NullPointerException - thrown if, and only if, key is nullpublic static Logger newInstance()
Logger instance.
To configure it, you can do that manually, or let the current LoggerConfigurator do it for you, by calling LoggerConfigurator.configure(logger).
Logger instance