一、前言
关于log4j2中log4j-core源码包org.apache.logging.log4j.core.tools.Generate自定义日志扩展源码生成器,可以自定义日志级别添加到现有日志级别、自定义的日志文件替换现有日志级别等。
二、源码说明
1.Generator类
package org.apache.logging.log4j.core.tools;@b@@b@import java.io.PrintStream;@b@import java.util.ArrayList;@b@import java.util.Arrays;@b@import java.util.List;@b@@b@/**@b@ * Generates source code for custom or extended logger wrappers.@b@ * <p>@b@ * Usage:@b@ * <p>@b@ * To generate source code for an extended logger that adds custom log levels to the existing ones: <br>@b@ * {@code java org.apache.logging.log4j.core.tools.Generate$ExtendedLogger <logger.class.name> <CUSTOMLEVEL>=<WEIGHT>@b@ * [CUSTOMLEVEL2=WEIGHT2 [CUSTOMLEVEL3=WEIGHT3] ...]}@b@ * <p>@b@ * Example of creating an extended logger:<br>@b@ * {@code java org.apache.logging.log4j.core.tools.Generate$ExtendedLogger com.mycomp.ExtLogger DIAG=350 NOTICE=450@b@ * VERBOSE=550}@b@ * <p>@b@ * To generate source code for a custom logger that replaces the existing log levels with custom ones: <br>@b@ * {@code java org.apache.logging.log4j.core.tools.Generate$CustomLogger <logger.class.name> <CUSTOMLEVEL>=<WEIGHT>@b@ * [CUSTOMLEVEL2=WEIGHT2 [CUSTOMLEVEL3=WEIGHT3] ...]}@b@ * <p>@b@ * Example of creating a custom logger:<br>@b@ * {@code java org.apache.logging.log4j.core.tools.Generate$CustomLogger com.mycomp.MyLogger DEFCON1=350 DEFCON2=450@b@ * DEFCON3=550}@b@ */@b@public final class Generate {@b@ // Implementation note:@b@ // The generated code is in the user's namespace which has its own versioning scheme, so@b@ // any @since tags in the generated code deliberately mention "Log4j-2.x" rather than just the log4j version number.@b@@b@ static final String PACKAGE_DECLARATION = "package %s;%n%n";@b@@b@ static enum Type {@b@ CUSTOM {@b@ @Override@b@ String imports() {@b@ //@formatter:off@b@ return "" @b@ + "import java.io.Serializable;%n" @b@ + "import org.apache.logging.log4j.Level;%n" @b@ + "import org.apache.logging.log4j.LogManager;%n" @b@ + "import org.apache.logging.log4j.Logger;%n" @b@ + "import org.apache.logging.log4j.Marker;%n" @b@ + "import org.apache.logging.log4j.message.Message;%n" @b@ + "import org.apache.logging.log4j.message.MessageFactory;%n" @b@ + "import org.apache.logging.log4j.spi.AbstractLogger;%n" @b@ + "import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;%n" @b@ + "import org.apache.logging.log4j.util.MessageSupplier;%n" @b@ + "import org.apache.logging.log4j.util.Supplier;%n"@b@ + "%n";@b@ //@formatter:on@b@ }@b@@b@ @Override@b@ String declaration() {@b@ //@formatter:off@b@ return "" @b@ + "/**%n" @b@ + " * Custom Logger interface with convenience methods for%n" @b@ + " * %s%n" @b@ + " * <p>Compatible with Log4j 2.6 or higher.</p>%n" @b@ + " */%n" @b@ + "public final class %s implements Serializable {%n" @b@ + " private static final long serialVersionUID = " + System.nanoTime() + "L;%n" @b@ + " private final ExtendedLoggerWrapper logger;%n" @b@ + "%n";@b@ //@formatter:on@b@ }@b@@b@ @Override@b@ String constructor() {@b@ //@formatter:off@b@ return "" @b@ + "%n" @b@ + " private %s(final Logger logger) {%n" @b@ + " this.logger = new ExtendedLoggerWrapper((AbstractLogger) logger, logger.getName(), "@b@ + "logger.getMessageFactory());%n" @b@ + " }%n";@b@ //@formatter:on@b@ }@b@@b@ @Override@b@ Class<?> generator() {@b@ return CustomLogger.class;@b@ }@b@ },@b@ EXTEND {@b@ @Override@b@ String imports() {@b@ //@formatter:off@b@ return "" @b@ + "import org.apache.logging.log4j.Level;%n" @b@ + "import org.apache.logging.log4j.LogManager;%n" @b@ + "import org.apache.logging.log4j.Logger;%n" @b@ + "import org.apache.logging.log4j.Marker;%n" @b@ + "import org.apache.logging.log4j.message.Message;%n" @b@ + "import org.apache.logging.log4j.message.MessageFactory;%n" @b@ + "import org.apache.logging.log4j.spi.AbstractLogger;%n" @b@ + "import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;%n" @b@ + "import org.apache.logging.log4j.util.MessageSupplier;%n" @b@ + "import org.apache.logging.log4j.util.Supplier;%n"@b@ + "%n";@b@ //@formatter:on@b@ }@b@@b@ @Override@b@ String declaration() {@b@ //@formatter:off@b@ return "" @b@ + "/**%n" @b@ + " * Extended Logger interface with convenience methods for%n" @b@ + " * %s%n" @b@ + " * <p>Compatible with Log4j 2.6 or higher.</p>%n" @b@ + " */%n" @b@ + "public final class %s extends ExtendedLoggerWrapper {%n" @b@ + " private static final long serialVersionUID = " + System.nanoTime() + "L;%n" @b@ + " private final ExtendedLoggerWrapper logger;%n" @b@ + "%n";@b@ //@formatter:on@b@ }@b@@b@ @Override@b@ String constructor() {@b@ //@formatter:off@b@ return "" @b@ + "%n" @b@ + " private %s(final Logger logger) {%n" @b@ + " super((AbstractLogger) logger, logger.getName(), logger.getMessageFactory());%n" @b@ + " this.logger = this;%n" @b@ + " }%n";@b@ //@formatter:on@b@ }@b@@b@ @Override@b@ Class<?> generator() {@b@ return ExtendedLogger.class;@b@ }@b@ };@b@ abstract String imports();@b@@b@ abstract String declaration();@b@@b@ abstract String constructor();@b@@b@ abstract Class<?> generator();@b@ }@b@@b@ static final String FQCN_FIELD = "" @b@ + " private static final String FQCN = %s.class.getName();%n";@b@@b@ static final String LEVEL_FIELD = "" @b@ + " private static final Level %s = Level.forName(\"%s\", %d);%n";@b@@b@ static final String FACTORY_METHODS = "" @b@ //@formatter:off@b@ + "%n" @b@ + " /**%n" @b@ + " * Returns a custom Logger with the name of the calling class.%n" @b@ + " * %n" @b@ + " * @return The custom Logger for the calling class.%n" @b@ + " */%n" @b@ + " public static CLASSNAME create() {%n" @b@ + " final Logger wrapped = LogManager.getLogger();%n" @b@ + " return new CLASSNAME(wrapped);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Returns a custom Logger using the fully qualified name of the Class as%n" @b@ + " * the Logger name.%n" @b@ + " * %n" @b@ + " * @param loggerName The Class whose name should be used as the Logger name.%n" @b@ + " * If null it will default to the calling class.%n" @b@ + " * @return The custom Logger.%n" @b@ + " */%n" @b@ + " public static CLASSNAME create(final Class<?> loggerName) {%n" @b@ + " final Logger wrapped = LogManager.getLogger(loggerName);%n" @b@ + " return new CLASSNAME(wrapped);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Returns a custom Logger using the fully qualified name of the Class as%n" @b@ + " * the Logger name.%n" @b@ + " * %n" @b@ + " * @param loggerName The Class whose name should be used as the Logger name.%n" @b@ + " * If null it will default to the calling class.%n" @b@ + " * @param messageFactory The message factory is used only when creating a%n" @b@ + " * logger, subsequent use does not change the logger but will log%n" @b@ + " * a warning if mismatched.%n" @b@ + " * @return The custom Logger.%n" @b@ + " */%n" @b@ + " public static CLASSNAME create(final Class<?> loggerName, final MessageFactory" @b@ + " messageFactory) {%n" @b@ + " final Logger wrapped = LogManager.getLogger(loggerName, messageFactory);%n" @b@ + " return new CLASSNAME(wrapped);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Returns a custom Logger using the fully qualified class name of the value%n" @b@ + " * as the Logger name.%n" @b@ + " * %n" @b@ + " * @param value The value whose class name should be used as the Logger%n" @b@ + " * name. If null the name of the calling class will be used as%n" @b@ + " * the logger name.%n" @b@ + " * @return The custom Logger.%n" @b@ + " */%n" @b@ + " public static CLASSNAME create(final Object value) {%n" @b@ + " final Logger wrapped = LogManager.getLogger(value);%n" @b@ + " return new CLASSNAME(wrapped);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Returns a custom Logger using the fully qualified class name of the value%n" @b@ + " * as the Logger name.%n" @b@ + " * %n" @b@ + " * @param value The value whose class name should be used as the Logger%n" @b@ + " * name. If null the name of the calling class will be used as%n" @b@ + " * the logger name.%n" @b@ + " * @param messageFactory The message factory is used only when creating a%n" @b@ + " * logger, subsequent use does not change the logger but will log%n" @b@ + " * a warning if mismatched.%n" @b@ + " * @return The custom Logger.%n" @b@ + " */%n" @b@ + " public static CLASSNAME create(final Object value, final MessageFactory messageFactory) {%n" @b@ + " final Logger wrapped = LogManager.getLogger(value, messageFactory);%n" @b@ + " return new CLASSNAME(wrapped);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Returns a custom Logger with the specified name.%n" @b@ + " * %n" @b@ + " * @param name The logger name. If null the name of the calling class will%n" @b@ + " * be used.%n" @b@ + " * @return The custom Logger.%n" @b@ + " */%n" @b@ + " public static CLASSNAME create(final String name) {%n" @b@ + " final Logger wrapped = LogManager.getLogger(name);%n" @b@ + " return new CLASSNAME(wrapped);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Returns a custom Logger with the specified name.%n" @b@ + " * %n" @b@ + " * @param name The logger name. If null the name of the calling class will%n" @b@ + " * be used.%n" @b@ + " * @param messageFactory The message factory is used only when creating a%n" @b@ + " * logger, subsequent use does not change the logger but will log%n" @b@ + " * a warning if mismatched.%n" @b@ + " * @return The custom Logger.%n" @b@ + " */%n" @b@ + " public static CLASSNAME create(final String name, final MessageFactory messageFactory) {%n" @b@ + " final Logger wrapped = LogManager.getLogger(name, messageFactory);%n" @b@ + " return new CLASSNAME(wrapped);%n" @b@ + " }%n";@b@ //@formatter:on@b@@b@ static final String METHODS = "" @b@ //@formatter:off@b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with the specific Marker at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param msg the message string to be logged%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final Message msg) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, msg, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with the specific Marker at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param msg the message string to be logged%n" @b@ + " * @param t A Throwable or null.%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final Message msg, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, msg, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message object with the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message object to log.%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final Object message) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message CharSequence with the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message CharSequence to log.%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final CharSequence message) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message at the {@code CUSTOM_LEVEL} level including the stack trace of%n" @b@ + " * the {@link Throwable} {@code t} passed as parameter.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final Object message, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message at the {@code CUSTOM_LEVEL} level including the stack trace of%n" @b@ + " * the {@link Throwable} {@code t} passed as parameter.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the CharSequence to log.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final CharSequence message, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message object with the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message object to log.%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param params parameters to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object... params) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, params);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1) {%n"@b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2, p3);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2, p3, p4);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2, p3, p4, p5);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2, p3, p4, p5, p6);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @param p7 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6,%n" @b@ + " final Object p7) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2, p3, p4, p5, p6, p7);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @param p7 parameter to the message.%n" @b@ + " * @param p8 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6,%n" @b@ + " final Object p7, final Object p8) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2, p3, p4, p5, p6, p7, " @b@ + "p8);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @param p7 parameter to the message.%n" @b@ + " * @param p8 parameter to the message.%n" @b@ + " * @param p9 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6,%n" @b@ + " final Object p7, final Object p8, final Object p9) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, p0, p1, p2, p3, p4, p5, p6, p7, " @b@ + "p8, p9);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message at the {@code CUSTOM_LEVEL} level including the stack trace of%n" @b@ + " * the {@link Throwable} {@code t} passed as parameter.%n" @b@ + " * %n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs the specified Message at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param msg the message string to be logged%n" @b@ + " */%n" @b@ + " public void methodName(final Message msg) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, msg, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs the specified Message at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param msg the message string to be logged%n" @b@ + " * @param t A Throwable or null.%n" @b@ + " */%n" @b@ + " public void methodName(final Message msg, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, msg, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message object with the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message object to log.%n" @b@ + " */%n" @b@ + " public void methodName(final Object message) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message at the {@code CUSTOM_LEVEL} level including the stack trace of%n" @b@ + " * the {@link Throwable} {@code t} passed as parameter.%n" @b@ + " * %n" @b@ + " * @param message the message to log.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " */%n" @b@ + " public void methodName(final Object message, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message CharSequence with the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message CharSequence to log.%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final CharSequence message) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a CharSequence at the {@code CUSTOM_LEVEL} level including the stack trace of%n" @b@ + " * the {@link Throwable} {@code t} passed as parameter.%n" @b@ + " * %n" @b@ + " * @param message the CharSequence to log.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final CharSequence message, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message object with the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message object to log.%n" @b@ + " */%n" @b@ + " public void methodName(final String message) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n"@b@ + " * @param params parameters to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object... params) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, params);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2, p3);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2, p3, p4);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2, p3, p4, p5);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2, p3, p4, p5, p6);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @param p7 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6,%n" @b@ + " final Object p7) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2, p3, p4, p5, p6, p7);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @param p7 parameter to the message.%n" @b@ + " * @param p8 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6,%n" @b@ + " final Object p7, final Object p8) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2, p3, p4, p5, p6, p7, " @b@ + "p8);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters at the {@code CUSTOM_LEVEL} level.%n" @b@ + " * %n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param p0 parameter to the message.%n" @b@ + " * @param p1 parameter to the message.%n" @b@ + " * @param p2 parameter to the message.%n" @b@ + " * @param p3 parameter to the message.%n" @b@ + " * @param p4 parameter to the message.%n" @b@ + " * @param p5 parameter to the message.%n" @b@ + " * @param p6 parameter to the message.%n" @b@ + " * @param p7 parameter to the message.%n" @b@ + " * @param p8 parameter to the message.%n" @b@ + " * @param p9 parameter to the message.%n" @b@ + " * @see #getMessageFactory()%n" @b@ + " * @since Log4j-2.6%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Object p0, " @b@ + "final Object p1, final Object p2,%n" @b@ + " final Object p3, final Object p4, final Object p5, final Object p6,%n" @b@ + " final Object p7, final Object p8, final Object p9) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, p0, p1, p2, p3, p4, p5, p6, p7, " @b@ + "p8, p9);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message at the {@code CUSTOM_LEVEL} level including the stack trace of%n" @b@ + " * the {@link Throwable} {@code t} passed as parameter.%n" @b@ + " * %n" @b@ + " * @param message the message to log.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, t);%n" @b@ + " }%n"@b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message which is only to be constructed if the logging level is the {@code CUSTOM_LEVEL}"@b@ + "level.%n" @b@ + " *%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message;%n" @b@ + " * the format depends on the message factory.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final Supplier<?> msgSupplier) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, msgSupplier, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message (only to be constructed if the logging level is the {@code CUSTOM_LEVEL}%n" @b@ + " * level) including the stack trace of the {@link Throwable} <code>t</code> passed as parameter.%n"@b@ + " *%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message;%n" @b@ + " * the format depends on the message factory.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final Supplier<?> msgSupplier, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, msgSupplier, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message which is only to be constructed if the logging level is the%n" @b@ + " * {@code CUSTOM_LEVEL} level with the specified Marker.%n" @b@ + " *%n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message;%n" @b@ + " * the format depends on the message factory.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final Supplier<?> msgSupplier) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, msgSupplier, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters which are only to be constructed if the logging level is the%n" @b@ + " * {@code CUSTOM_LEVEL} level.%n" @b@ + " *%n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param paramSuppliers An array of functions, which when called, produce the desired log" @b@ + " message parameters.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final String message, final Supplier<?>..." @b@ + " paramSuppliers) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, message, paramSuppliers);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message (only to be constructed if the logging level is the {@code CUSTOM_LEVEL}%n" @b@ + " * level) with the specified Marker and including the stack trace of the {@link Throwable}%n" @b@ + " * <code>t</code> passed as parameter.%n"@b@ + " *%n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message;%n" @b@ + " * the format depends on the message factory.%n" @b@ + " * @param t A Throwable or null.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, msgSupplier, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message with parameters which are only to be constructed if the logging level is%n" @b@ + " * the {@code CUSTOM_LEVEL} level.%n" @b@ + " *%n" @b@ + " * @param message the message to log; the format depends on the message factory.%n" @b@ + " * @param paramSuppliers An array of functions, which when called, produce the desired log" @b@ + " message parameters.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final String message, final Supplier<?>... paramSuppliers) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, message, paramSuppliers);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message which is only to be constructed if the logging level is the%n" @b@ + " * {@code CUSTOM_LEVEL} level with the specified Marker. The {@code MessageSupplier} may or may%n" @b@ + " * not use the {@link MessageFactory} to construct the {@code Message}.%n" @b@ + " *%n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final MessageSupplier msgSupplier) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, msgSupplier, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message (only to be constructed if the logging level is the {@code CUSTOM_LEVEL}%n" @b@ + " * level) with the specified Marker and including the stack trace of the {@link Throwable}%n" @b@ + " * <code>t</code> passed as parameter. The {@code MessageSupplier} may or may not use the%n" @b@ + " * {@link MessageFactory} to construct the {@code Message}.%n"@b@ + " *%n" @b@ + " * @param marker the marker data specific to this log statement%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message.%n" @b@ + " * @param t A Throwable or null.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final Marker marker, final MessageSupplier msgSupplier, final " @b@ + "Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, marker, msgSupplier, t);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message which is only to be constructed if the logging level is the%n" @b@ + " * {@code CUSTOM_LEVEL} level. The {@code MessageSupplier} may or may not use the%n" @b@ + " * {@link MessageFactory} to construct the {@code Message}.%n"@b@ + " *%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final MessageSupplier msgSupplier) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, msgSupplier, (Throwable) null);%n" @b@ + " }%n" @b@ + "%n" @b@ + " /**%n" @b@ + " * Logs a message (only to be constructed if the logging level is the {@code CUSTOM_LEVEL}%n" @b@ + " * level) including the stack trace of the {@link Throwable} <code>t</code> passed as parameter.%n"@b@ + " * The {@code MessageSupplier} may or may not use the {@link MessageFactory} to construct the%n" @b@ + " * {@code Message}.%n"@b@ + " *%n" @b@ + " * @param msgSupplier A function, which when called, produces the desired log message.%n" @b@ + " * @param t the exception to log, including its stack trace.%n" @b@ + " * @since Log4j-2.4%n" @b@ + " */%n" @b@ + " public void methodName(final MessageSupplier msgSupplier, final Throwable t) {%n" @b@ + " logger.logIfEnabled(FQCN, CUSTOM_LEVEL, null, msgSupplier, t);%n" @b@ + " }%n";@b@ //@formatter:on@b@@b@ private Generate() {@b@ }@b@@b@ /**@b@ * Generates source code for custom logger wrappers that only provide convenience methods for the specified custom@b@ * levels, not for the standard built-in levels.@b@ */@b@ public static final class CustomLogger {@b@ /**@b@ * Generates source code for custom logger wrappers that only provide convenience methods for the specified@b@ * custom levels, not for the standard built-in levels.@b@ *@b@ * @param args className of the custom logger to generate, followed by a NAME=intLevel pair for each custom log@b@ * level to generate convenience methods for@b@ */@b@ public static void main(final String[] args) {@b@ generate(args, Type.CUSTOM);@b@ }@b@@b@ private CustomLogger() {@b@ }@b@ }@b@@b@ /**@b@ * Generates source code for extended logger wrappers that provide convenience methods for the specified custom@b@ * levels, and by extending {@code org.apache.logging.log4j.spi.ExtendedLoggerWrapper}, inherit the convenience@b@ * methods for the built-in levels provided by the {@code Logger} interface.@b@ */@b@ public static final class ExtendedLogger {@b@ /**@b@ * Generates source code for extended logger wrappers that provide convenience methods for the specified custom@b@ * levels.@b@ *@b@ * @param args className of the custom logger to generate, followed by a NAME=intLevel pair for each custom log@b@ * level to generate convenience methods for@b@ */@b@ public static void main(final String[] args) {@b@ generate(args, Type.EXTEND);@b@ }@b@@b@ private ExtendedLogger() {@b@ }@b@ }@b@@b@ static class LevelInfo {@b@ final String name;@b@ final int intLevel;@b@@b@ LevelInfo(final String description) {@b@ final String[] parts = description.split("=");@b@ name = parts[0];@b@ intLevel = Integer.parseInt(parts[1]);@b@ }@b@@b@ public static List<LevelInfo> parse(final List<String> values, final Class<?> generator) {@b@ final List<LevelInfo> result = new ArrayList<>(values.size());@b@ for (int i = 0; i < values.size(); i++) {@b@ try {@b@ result.add(new LevelInfo(values.get(i)));@b@ } catch (final Exception ex) {@b@ System.err.println("Cannot parse custom level '" + values.get(i) + "': " + ex.toString());@b@ usage(System.err, generator);@b@ System.exit(-1);@b@ }@b@ }@b@ return result;@b@ }@b@ }@b@@b@ private static void generate(final String[] args, final Type type) {@b@ generate(args, type, System.out);@b@ }@b@@b@ static void generate(final String[] args, final Type type, final PrintStream printStream) {@b@ if (!validate(args)) {@b@ usage(printStream, type.generator());@b@ System.exit(-1);@b@ }@b@ final List<String> values = new ArrayList<>(Arrays.asList(args));@b@ final String classFQN = values.remove(0);@b@ final List<LevelInfo> levels = LevelInfo.parse(values, type.generator());@b@ printStream.println(generateSource(classFQN, levels, type));@b@ }@b@@b@ static boolean validate(final String[] args) {@b@ if (args.length < 2) {@b@ return false;@b@ }@b@ return true;@b@ }@b@@b@ private static void usage(final PrintStream out, final Class<?> generator) {@b@ out.println("Usage: java " + generator.getName() + " className LEVEL1=intLevel1 [LEVEL2=intLevel2...]");@b@ out.println(" Where className is the fully qualified class name of the custom/extended logger");@b@ out.println(" to generate, followed by a space-separated list of custom log levels.");@b@ out.println(" For each custom log level, specify NAME=intLevel (without spaces).");@b@ }@b@@b@ static String generateSource(final String classNameFQN, final List<LevelInfo> levels, final Type type) {@b@ final StringBuilder sb = new StringBuilder(10000 * levels.size());@b@ final int lastDot = classNameFQN.lastIndexOf('.');@b@ final String pkg = classNameFQN.substring(0, lastDot >= 0 ? lastDot : 0);@b@ if (!pkg.isEmpty()) {@b@ sb.append(String.format(PACKAGE_DECLARATION, pkg));@b@ }@b@ sb.append(String.format(type.imports(), ""));@b@ final String className = classNameFQN.substring(classNameFQN.lastIndexOf('.') + 1);@b@ final String javadocDescr = javadocDescription(levels);@b@ sb.append(String.format(type.declaration(), javadocDescr, className));@b@ sb.append(String.format(FQCN_FIELD, className));@b@ for (final LevelInfo level : levels) {@b@ sb.append(String.format(LEVEL_FIELD, level.name, level.name, level.intLevel));@b@ }@b@ sb.append(String.format(type.constructor(), className));@b@ sb.append(String.format(FACTORY_METHODS.replaceAll("CLASSNAME", className), ""));@b@ for (final LevelInfo level : levels) {@b@ final String methodName = camelCase(level.name);@b@ final String phase1 = METHODS.replaceAll("CUSTOM_LEVEL", level.name);@b@ final String phase2 = phase1.replaceAll("methodName", methodName);@b@ sb.append(String.format(phase2, ""));@b@ }@b@@b@ sb.append('}');@b@ sb.append(System.getProperty("line.separator"));@b@ return sb.toString();@b@ }@b@@b@ static String javadocDescription(final List<LevelInfo> levels) {@b@ if (levels.size() == 1) {@b@ return "the " + levels.get(0).name + " custom log level.";@b@ }@b@ final StringBuilder sb = new StringBuilder(512);@b@ sb.append("the ");@b@ String sep = "";@b@ for (int i = 0; i < levels.size(); i++) {@b@ sb.append(sep);@b@ sb.append(levels.get(i).name);@b@ sep = (i == levels.size() - 2) ? " and " : ", ";@b@ }@b@ sb.append(" custom log levels.");@b@ return sb.toString();@b@ }@b@@b@ static String camelCase(final String customLevel) {@b@ final StringBuilder sb = new StringBuilder(customLevel.length());@b@ boolean lower = true;@b@ for (final char ch : customLevel.toCharArray()) {@b@ if (ch == '_') {@b@ lower = false;@b@ continue;@b@ }@b@ sb.append(lower ? Character.toLowerCase(ch) : Character.toUpperCase(ch));@b@ lower = true;@b@ }@b@ return sb.toString();@b@ }@b@}
2.ExtendedLoggerGenerator扩展生成器类
package org.apache.logging.log4j.core.tools;@b@@b@/**@b@ * Wrapper around {@link Generate.ExtendedLogger}.@b@ */@b@public class ExtendedLoggerGenerator {@b@ /**@b@ * Delegates to {@link Generate.ExtendedLogger#main(String[])}@b@ * @param args the command line arguments to pass on@b@ */@b@ public static void main(final String[] args) {@b@ Generate.ExtendedLogger.main(args);@b@ }@b@}
3.CustomLoggerGenerator自定义生成器类
package org.apache.logging.log4j.core.tools;@b@@b@/**@b@ * Wrapper around {@link Generate.CustomLogger}.@b@ */@b@public class CustomLoggerGenerator {@b@ /**@b@ * Delegates to {@link Generate.CustomLogger#main(String[])}@b@ * @param args the command line arguments to pass on@b@ */@b@ public static void main(final String[] args) {@b@ Generate.CustomLogger.main(args);@b@ }@b@}