package org.myorg;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.MessageFactory;
import org.apache.logging.log4j.spi.AbstractLogger;
import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
/**
* Extended Logger interface with convenience methods for
* the DIAG, NOTICE and VERBOSE custom log levels.
*/
public final class MyExtendedLogger extends ExtendedLoggerWrapper {
private static final long serialVersionUID = 1408253285605196000L;
private final ExtendedLoggerWrapper logger;
private static final String FQCN = MyExtendedLogger.class.getName();
private static final Level DIAG = Level.forName("DIAG", 350);
private static final Level NOTICE = Level.forName("NOTICE", 450);
private static final Level VERBOSE = Level.forName("VERBOSE", 550);
private MyExtendedLogger(final Logger logger) {
super((AbstractLogger) logger, logger.getName(), logger.getMessageFactory());
this.logger = this;
}
/**
* Returns a custom Logger with the name of the calling class.
*
* @return The custom Logger for the calling class.
*/
public static MyExtendedLogger create() {
final Logger wrapped = LogManager.getLogger();
return new MyExtendedLogger(wrapped);
}
/**
* Returns a custom Logger using the fully qualified name of the Class as
* the Logger name.
*
* @param loggerName The Class whose name should be used as the Logger name.
* If null it will default to the calling class.
* @return The custom Logger.
*/
public static MyExtendedLogger create(final Class<?> loggerName) {
final Logger wrapped = LogManager.getLogger(loggerName);
return new MyExtendedLogger(wrapped);
}
/**
* Returns a custom Logger using the fully qualified name of the Class as
* the Logger name.
*
* @param loggerName The Class whose name should be used as the Logger name.
* If null it will default to the calling class.
* @param messageFactory The message factory is used only when creating a
* logger, subsequent use does not change the logger but will log
* a warning if mismatched.
* @return The custom Logger.
*/
public static MyExtendedLogger create(final Class<?> loggerName, final MessageFactory factory) {
final Logger wrapped = LogManager.getLogger(loggerName, factory);
return new MyExtendedLogger(wrapped);
}
/**
* Returns a custom Logger using the fully qualified class name of the value
* as the Logger name.
*
* @param value The value whose class name should be used as the Logger
* name. If null the name of the calling class will be used as
* the logger name.
* @return The custom Logger.
*/
public static MyExtendedLogger create(final Object value) {
final Logger wrapped = LogManager.getLogger(value);
return new MyExtendedLogger(wrapped);
}
/**
* Returns a custom Logger using the fully qualified class name of the value
* as the Logger name.
*
* @param value The value whose class name should be used as the Logger
* name. If null the name of the calling class will be used as
* the logger name.
* @param messageFactory The message factory is used only when creating a
* logger, subsequent use does not change the logger but will log
* a warning if mismatched.
* @return The custom Logger.
*/
public static MyExtendedLogger create(final Object value, final MessageFactory factory) {
final Logger wrapped = LogManager.getLogger(value, factory);
return new MyExtendedLogger(wrapped);
}
/**
* Returns a custom Logger with the specified name.
*
* @param name The logger name. If null the name of the calling class will
* be used.
* @return The custom Logger.
*/
public static MyExtendedLogger create(final String name) {
final Logger wrapped = LogManager.getLogger(name);
return new MyExtendedLogger(wrapped);
}
/**
* Returns a custom Logger with the specified name.
*
* @param name The logger name. If null the name of the calling class will
* be used.
* @param messageFactory The message factory is used only when creating a
* logger, subsequent use does not change the logger but will log
* a warning if mismatched.
* @return The custom Logger.
*/
public static MyExtendedLogger create(final String name, final MessageFactory factory) {
final Logger wrapped = LogManager.getLogger(name, factory);
return new MyExtendedLogger(wrapped);
}
/**
* Logs a message with the specific Marker at the {@code DIAG} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
*/
public void diag(final Marker marker, final Message msg) {
logger.logIfEnabled(FQCN, DIAG, marker, msg, (Throwable) null);
}
/**
* Logs a message with the specific Marker at the {@code DIAG} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void diag(final Marker marker, final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DIAG, marker, msg, t);
}
/**
* Logs a message object with the {@code DIAG} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void diag(final Marker marker, final Object message) {
logger.logIfEnabled(FQCN, DIAG, marker, message, (Throwable) null);
}
/**
* Logs a message at the {@code DIAG} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param marker the marker data specific to this log statement
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void diag(final Marker marker, final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DIAG, marker, message, t);
}
/**
* Logs a message object with the {@code DIAG} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void diag(final Marker marker, final String message) {
logger.logIfEnabled(FQCN, DIAG, marker, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DIAG} level.
*
* @param marker the marker data specific to this log statement
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void diag(final Marker marker, final String message, final Object... params) {
logger.logIfEnabled(FQCN, DIAG, marker, message, params);
}
/**
* Logs a message at the {@code DIAG} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param marker the marker data specific to this log statement
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void diag(final Marker marker, final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DIAG, marker, message, t);
}
/**
* Logs the specified Message at the {@code DIAG} level.
*
* @param msg the message string to be logged
*/
public void diag(final Message msg) {
logger.logIfEnabled(FQCN, DIAG, null, msg, (Throwable) null);
}
/**
* Logs the specified Message at the {@code DIAG} level.
*
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void diag(final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DIAG, null, msg, t);
}
/**
* Logs a message object with the {@code DIAG} level.
*
* @param message the message object to log.
*/
public void diag(final Object message) {
logger.logIfEnabled(FQCN, DIAG, null, message, (Throwable) null);
}
/**
* Logs a message at the {@code DIAG} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void diag(final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DIAG, null, message, t);
}
/**
* Logs a message object with the {@code DIAG} level.
*
* @param message the message object to log.
*/
public void diag(final String message) {
logger.logIfEnabled(FQCN, DIAG, null, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DIAG} level.
*
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void diag(final String message, final Object... params) {
logger.logIfEnabled(FQCN, DIAG, null, message, params);
}
/**
* Logs a message at the {@code DIAG} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void diag(final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DIAG, null, message, t);
}
/**
* Logs a message with the specific Marker at the {@code NOTICE} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
*/
public void notice(final Marker marker, final Message msg) {
logger.logIfEnabled(FQCN, NOTICE, marker, msg, (Throwable) null);
}
/**
* Logs a message with the specific Marker at the {@code NOTICE} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void notice(final Marker marker, final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, NOTICE, marker, msg, t);
}
/**
* Logs a message object with the {@code NOTICE} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void notice(final Marker marker, final Object message) {
logger.logIfEnabled(FQCN, NOTICE, marker, message, (Throwable) null);
}
/**
* Logs a message at the {@code NOTICE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param marker the marker data specific to this log statement
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void notice(final Marker marker, final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, NOTICE, marker, message, t);
}
/**
* Logs a message object with the {@code NOTICE} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void notice(final Marker marker, final String message) {
logger.logIfEnabled(FQCN, NOTICE, marker, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code NOTICE} level.
*
* @param marker the marker data specific to this log statement
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void notice(final Marker marker, final String message, final Object... params) {
logger.logIfEnabled(FQCN, NOTICE, marker, message, params);
}
/**
* Logs a message at the {@code NOTICE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param marker the marker data specific to this log statement
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void notice(final Marker marker, final String message, final Throwable t) {
logger.logIfEnabled(FQCN, NOTICE, marker, message, t);
}
/**
* Logs the specified Message at the {@code NOTICE} level.
*
* @param msg the message string to be logged
*/
public void notice(final Message msg) {
logger.logIfEnabled(FQCN, NOTICE, null, msg, (Throwable) null);
}
/**
* Logs the specified Message at the {@code NOTICE} level.
*
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void notice(final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, NOTICE, null, msg, t);
}
/**
* Logs a message object with the {@code NOTICE} level.
*
* @param message the message object to log.
*/
public void notice(final Object message) {
logger.logIfEnabled(FQCN, NOTICE, null, message, (Throwable) null);
}
/**
* Logs a message at the {@code NOTICE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void notice(final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, NOTICE, null, message, t);
}
/**
* Logs a message object with the {@code NOTICE} level.
*
* @param message the message object to log.
*/
public void notice(final String message) {
logger.logIfEnabled(FQCN, NOTICE, null, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code NOTICE} level.
*
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void notice(final String message, final Object... params) {
logger.logIfEnabled(FQCN, NOTICE, null, message, params);
}
/**
* Logs a message at the {@code NOTICE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void notice(final String message, final Throwable t) {
logger.logIfEnabled(FQCN, NOTICE, null, message, t);
}
/**
* Logs a message with the specific Marker at the {@code VERBOSE} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
*/
public void verbose(final Marker marker, final Message msg) {
logger.logIfEnabled(FQCN, VERBOSE, marker, msg, (Throwable) null);
}
/**
* Logs a message with the specific Marker at the {@code VERBOSE} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void verbose(final Marker marker, final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, VERBOSE, marker, msg, t);
}
/**
* Logs a message object with the {@code VERBOSE} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void verbose(final Marker marker, final Object message) {
logger.logIfEnabled(FQCN, VERBOSE, marker, message, (Throwable) null);
}
/**
* Logs a message at the {@code VERBOSE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param marker the marker data specific to this log statement
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void verbose(final Marker marker, final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, VERBOSE, marker, message, t);
}
/**
* Logs a message object with the {@code VERBOSE} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void verbose(final Marker marker, final String message) {
logger.logIfEnabled(FQCN, VERBOSE, marker, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code VERBOSE} level.
*
* @param marker the marker data specific to this log statement
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void verbose(final Marker marker, final String message, final Object... params) {
logger.logIfEnabled(FQCN, VERBOSE, marker, message, params);
}
/**
* Logs a message at the {@code VERBOSE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param marker the marker data specific to this log statement
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void verbose(final Marker marker, final String message, final Throwable t) {
logger.logIfEnabled(FQCN, VERBOSE, marker, message, t);
}
/**
* Logs the specified Message at the {@code VERBOSE} level.
*
* @param msg the message string to be logged
*/
public void verbose(final Message msg) {
logger.logIfEnabled(FQCN, VERBOSE, null, msg, (Throwable) null);
}
/**
* Logs the specified Message at the {@code VERBOSE} level.
*
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void verbose(final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, VERBOSE, null, msg, t);
}
/**
* Logs a message object with the {@code VERBOSE} level.
*
* @param message the message object to log.
*/
public void verbose(final Object message) {
logger.logIfEnabled(FQCN, VERBOSE, null, message, (Throwable) null);
}
/**
* Logs a message at the {@code VERBOSE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void verbose(final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, VERBOSE, null, message, t);
}
/**
* Logs a message object with the {@code VERBOSE} level.
*
* @param message the message object to log.
*/
public void verbose(final String message) {
logger.logIfEnabled(FQCN, VERBOSE, null, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code VERBOSE} level.
*
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void verbose(final String message, final Object... params) {
logger.logIfEnabled(FQCN, VERBOSE, null, message, params);
}
/**
* Logs a message at the {@code VERBOSE} level including the stack trace of
* the {@link Throwable} {@code t} passed as parameter.
*
* @param message the message to log.
* @param t the exception to log, including its stack trace.
*/
public void verbose(final String message, final Throwable t) {
logger.logIfEnabled(FQCN, VERBOSE, null, message, t);
}
}