package org.myorg;
import java.io.Serializable;
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;
/**
* Custom Logger interface with convenience methods for
* the DEFCON1, DEFCON2 and DEFCON3 custom log levels.
*/
public final class MyCustomLogger implements Serializable {
private static final long serialVersionUID = 1406681793304256000L;
private final ExtendedLoggerWrapper logger;
private static final String FQCN = MyCustomLogger.class.getName();
private static final Level DEFCON1 = Level.forName("DEFCON1", 350);
private static final Level DEFCON2 = Level.forName("DEFCON2", 450);
private static final Level DEFCON3 = Level.forName("DEFCON3", 550);
private MyCustomLogger(final Logger logger) {
this.logger = new ExtendedLoggerWrapper((AbstractLogger) logger, logger.getName(), logger.getMessageFactory());
}
/**
* Returns a custom Logger with the name of the calling class.
*
* @return The custom Logger for the calling class.
*/
public static MyCustomLogger create() {
final Logger wrapped = LogManager.getLogger();
return new MyCustomLogger(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 MyCustomLogger create(final Class<?> loggerName) {
final Logger wrapped = LogManager.getLogger(loggerName);
return new MyCustomLogger(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 MyCustomLogger create(final Class<?> loggerName, final MessageFactory factory) {
final Logger wrapped = LogManager.getLogger(loggerName, factory);
return new MyCustomLogger(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 MyCustomLogger create(final Object value) {
final Logger wrapped = LogManager.getLogger(value);
return new MyCustomLogger(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 MyCustomLogger create(final Object value, final MessageFactory factory) {
final Logger wrapped = LogManager.getLogger(value, factory);
return new MyCustomLogger(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 MyCustomLogger create(final String name) {
final Logger wrapped = LogManager.getLogger(name);
return new MyCustomLogger(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 MyCustomLogger create(final String name, final MessageFactory factory) {
final Logger wrapped = LogManager.getLogger(name, factory);
return new MyCustomLogger(wrapped);
}
/**
* Logs a message with the specific Marker at the {@code DEFCON1} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
*/
public void defcon1(final Marker marker, final Message msg) {
logger.logIfEnabled(FQCN, DEFCON1, marker, msg, (Throwable) null);
}
/**
* Logs a message with the specific Marker at the {@code DEFCON1} 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 defcon1(final Marker marker, final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON1, marker, msg, t);
}
/**
* Logs a message object with the {@code DEFCON1} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void defcon1(final Marker marker, final Object message) {
logger.logIfEnabled(FQCN, DEFCON1, marker, message, (Throwable) null);
}
/**
* Logs a message at the {@code DEFCON1} 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 defcon1(final Marker marker, final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON1, marker, message, t);
}
/**
* Logs a message object with the {@code DEFCON1} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void defcon1(final Marker marker, final String message) {
logger.logIfEnabled(FQCN, DEFCON1, marker, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DEFCON1} 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 defcon1(final Marker marker, final String message, final Object... params) {
logger.logIfEnabled(FQCN, DEFCON1, marker, message, params);
}
/**
* Logs a message at the {@code DEFCON1} 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 defcon1(final Marker marker, final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON1, marker, message, t);
}
/**
* Logs the specified Message at the {@code DEFCON1} level.
*
* @param msg the message string to be logged
*/
public void defcon1(final Message msg) {
logger.logIfEnabled(FQCN, DEFCON1, null, msg, (Throwable) null);
}
/**
* Logs the specified Message at the {@code DEFCON1} level.
*
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void defcon1(final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON1, null, msg, t);
}
/**
* Logs a message object with the {@code DEFCON1} level.
*
* @param message the message object to log.
*/
public void defcon1(final Object message) {
logger.logIfEnabled(FQCN, DEFCON1, null, message, (Throwable) null);
}
/**
* Logs a message at the {@code DEFCON1} 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 defcon1(final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON1, null, message, t);
}
/**
* Logs a message object with the {@code DEFCON1} level.
*
* @param message the message object to log.
*/
public void defcon1(final String message) {
logger.logIfEnabled(FQCN, DEFCON1, null, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DEFCON1} level.
*
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void defcon1(final String message, final Object... params) {
logger.logIfEnabled(FQCN, DEFCON1, null, message, params);
}
/**
* Logs a message at the {@code DEFCON1} 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 defcon1(final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON1, null, message, t);
}
/**
* Logs a message with the specific Marker at the {@code DEFCON2} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
*/
public void defcon2(final Marker marker, final Message msg) {
logger.logIfEnabled(FQCN, DEFCON2, marker, msg, (Throwable) null);
}
/**
* Logs a message with the specific Marker at the {@code DEFCON2} 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 defcon2(final Marker marker, final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON2, marker, msg, t);
}
/**
* Logs a message object with the {@code DEFCON2} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void defcon2(final Marker marker, final Object message) {
logger.logIfEnabled(FQCN, DEFCON2, marker, message, (Throwable) null);
}
/**
* Logs a message at the {@code DEFCON2} 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 defcon2(final Marker marker, final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON2, marker, message, t);
}
/**
* Logs a message object with the {@code DEFCON2} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void defcon2(final Marker marker, final String message) {
logger.logIfEnabled(FQCN, DEFCON2, marker, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DEFCON2} 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 defcon2(final Marker marker, final String message, final Object... params) {
logger.logIfEnabled(FQCN, DEFCON2, marker, message, params);
}
/**
* Logs a message at the {@code DEFCON2} 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 defcon2(final Marker marker, final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON2, marker, message, t);
}
/**
* Logs the specified Message at the {@code DEFCON2} level.
*
* @param msg the message string to be logged
*/
public void defcon2(final Message msg) {
logger.logIfEnabled(FQCN, DEFCON2, null, msg, (Throwable) null);
}
/**
* Logs the specified Message at the {@code DEFCON2} level.
*
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void defcon2(final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON2, null, msg, t);
}
/**
* Logs a message object with the {@code DEFCON2} level.
*
* @param message the message object to log.
*/
public void defcon2(final Object message) {
logger.logIfEnabled(FQCN, DEFCON2, null, message, (Throwable) null);
}
/**
* Logs a message at the {@code DEFCON2} 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 defcon2(final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON2, null, message, t);
}
/**
* Logs a message object with the {@code DEFCON2} level.
*
* @param message the message object to log.
*/
public void defcon2(final String message) {
logger.logIfEnabled(FQCN, DEFCON2, null, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DEFCON2} level.
*
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void defcon2(final String message, final Object... params) {
logger.logIfEnabled(FQCN, DEFCON2, null, message, params);
}
/**
* Logs a message at the {@code DEFCON2} 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 defcon2(final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON2, null, message, t);
}
/**
* Logs a message with the specific Marker at the {@code DEFCON3} level.
*
* @param marker the marker data specific to this log statement
* @param msg the message string to be logged
*/
public void defcon3(final Marker marker, final Message msg) {
logger.logIfEnabled(FQCN, DEFCON3, marker, msg, (Throwable) null);
}
/**
* Logs a message with the specific Marker at the {@code DEFCON3} 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 defcon3(final Marker marker, final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON3, marker, msg, t);
}
/**
* Logs a message object with the {@code DEFCON3} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void defcon3(final Marker marker, final Object message) {
logger.logIfEnabled(FQCN, DEFCON3, marker, message, (Throwable) null);
}
/**
* Logs a message at the {@code DEFCON3} 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 defcon3(final Marker marker, final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON3, marker, message, t);
}
/**
* Logs a message object with the {@code DEFCON3} level.
*
* @param marker the marker data specific to this log statement
* @param message the message object to log.
*/
public void defcon3(final Marker marker, final String message) {
logger.logIfEnabled(FQCN, DEFCON3, marker, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DEFCON3} 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 defcon3(final Marker marker, final String message, final Object... params) {
logger.logIfEnabled(FQCN, DEFCON3, marker, message, params);
}
/**
* Logs a message at the {@code DEFCON3} 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 defcon3(final Marker marker, final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON3, marker, message, t);
}
/**
* Logs the specified Message at the {@code DEFCON3} level.
*
* @param msg the message string to be logged
*/
public void defcon3(final Message msg) {
logger.logIfEnabled(FQCN, DEFCON3, null, msg, (Throwable) null);
}
/**
* Logs the specified Message at the {@code DEFCON3} level.
*
* @param msg the message string to be logged
* @param t A Throwable or null.
*/
public void defcon3(final Message msg, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON3, null, msg, t);
}
/**
* Logs a message object with the {@code DEFCON3} level.
*
* @param message the message object to log.
*/
public void defcon3(final Object message) {
logger.logIfEnabled(FQCN, DEFCON3, null, message, (Throwable) null);
}
/**
* Logs a message at the {@code DEFCON3} 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 defcon3(final Object message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON3, null, message, t);
}
/**
* Logs a message object with the {@code DEFCON3} level.
*
* @param message the message object to log.
*/
public void defcon3(final String message) {
logger.logIfEnabled(FQCN, DEFCON3, null, message, (Throwable) null);
}
/**
* Logs a message with parameters at the {@code DEFCON3} level.
*
* @param message the message to log; the format depends on the message factory.
* @param params parameters to the message.
* @see #getMessageFactory()
*/
public void defcon3(final String message, final Object... params) {
logger.logIfEnabled(FQCN, DEFCON3, null, message, params);
}
/**
* Logs a message at the {@code DEFCON3} 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 defcon3(final String message, final Throwable t) {
logger.logIfEnabled(FQCN, DEFCON3, null, message, t);
}
}