Java 类org.apache.logging.log4j.core.config.plugins.PluginConfiguration 实例源码

项目:log4j2-jsonevent-layout    文件:JSONLog4j2Layout.java   
/**
 * Creates the layout.
 *
 * @param locationInfo the location info
 * @param singleLine the single line
 * @param htmlSafe the html safe
 * @param plainContextMap the plain context map
 * @param charset the charset
 * @param userFields the user fields
 * @return the JSON log 4 j 2 layout
 */
@PluginFactory
public static JSONLog4j2Layout createLayout(
    // @formatter:off
        @PluginConfiguration final Configuration config,
        @PluginAttribute("locationInfo") boolean locationInfo,
        @PluginAttribute("singleLine") boolean singleLine,
        @PluginAttribute("htmlSafe") boolean htmlSafe,
        @PluginAttribute("plainContextMap") boolean plainContextMap, 
        @PluginAttribute("charset") Charset charset,
        @PluginElement("UserFields") final UserField[] userFields
    // @formatter:on
    ) {

    if(charset == null){
        charset = Charset.forName("UTF-8");
    }

    LOGGER.debug("Creating JSONLog4j2Layout {}",charset);
    return new JSONLog4j2Layout(locationInfo, singleLine, htmlSafe, plainContextMap, userFields, charset);
}
项目:log4j2    文件:LoggerConfig.java   
@PluginFactory
public static LoggerConfig createLogger(
        @PluginAttribute("additivity") final String additivity,
        @PluginAttribute("level") final String levelName,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("AppenderRef") final AppenderRef[] refs,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filters") final Filter filter) {
    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    Level level;
    try {
        level = Level.toLevel(levelName, Level.ERROR);
    } catch (final Exception ex) {
        LOGGER.error(
                "Invalid Log level specified: {}. Defaulting to Error",
                levelName);
        level = Level.ERROR;
    }
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new LoggerConfig(LogManager.ROOT_LOGGER_NAME, appenderRefs,
            filter, level, additive, properties, config,
            includeLocation(includeLocation));
}
项目:log4j2    文件:RewriteAppender.java   
/**
 * Create a RewriteAppender.
 * @param name The name of the Appender.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param appenderRefs An array of Appender names to call.
 * @param config The Configuration.
 * @param rewritePolicy The policy to use to modify the event.
 * @param filter A Filter to filter events.
 * @return The created RewriteAppender.
 */
@PluginFactory
public static RewriteAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginElement("AppenderRef") final AppenderRef[] appenderRefs,
        @PluginConfiguration final Configuration config,
        @PluginElement("RewritePolicy") final RewritePolicy rewritePolicy,
        @PluginElement("Filter") final Filter filter) {

    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    if (name == null) {
        LOGGER.error("No name provided for RewriteAppender");
        return null;
    }
    if (appenderRefs == null) {
        LOGGER.error("No appender references defined for RewriteAppender");
        return null;
    }
    return new RewriteAppender(name, filter, ignoreExceptions, appenderRefs, rewritePolicy, config);
}
项目:log4j2    文件:RoutingAppender.java   
/**
 * Create a RoutingAppender.
 * @param name The name of the Appender.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param routes The routing definitions.
 * @param config The Configuration (automatically added by the Configuration).
 * @param rewritePolicy A RewritePolicy, if any.
 * @param filter A Filter to restrict events processed by the Appender or null.
 * @return The RoutingAppender
 */
@PluginFactory
public static RoutingAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginElement("Routes") final Routes routes,
        @PluginConfiguration final Configuration config,
        @PluginElement("RewritePolicy") final RewritePolicy rewritePolicy,
        @PluginElement("Filters") final Filter filter) {

    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    if (name == null) {
        LOGGER.error("No name provided for RoutingAppender");
        return null;
    }
    if (routes == null) {
        LOGGER.error("No routes defined for RoutingAppender");
        return null;
    }
    return new RoutingAppender(name, filter, ignoreExceptions, routes, rewritePolicy, config);
}
项目:log4j2    文件:AsyncLoggerConfig.java   
@PluginFactory
public static LoggerConfig createLogger(
        @PluginAttribute("additivity") final String additivity,
        @PluginAttribute("level") final String levelName,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("AppenderRef") final AppenderRef[] refs,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filters") final Filter filter) {
    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    Level level;
    try {
        level = Level.toLevel(levelName, Level.ERROR);
    } catch (final Exception ex) {
        LOGGER.error(
                "Invalid Log level specified: {}. Defaulting to Error",
                levelName);
        level = Level.ERROR;
    }
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new AsyncLoggerConfig(LogManager.ROOT_LOGGER_NAME,
            appenderRefs, filter, level, additive, properties, config,
            includeLocation(includeLocation));
}
项目:mule-access-log    文件:CombinedAccessLogPatternLayout.java   
@PluginFactory
public static Layout createLayout(
        @PluginElement("Replace") final RegexReplacement replace,
        @PluginConfiguration final Configuration configuration,
        @PluginAttribute(value = "charset", defaultString = "UTF-8") final Charset charset,
        @PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions,
        @PluginAttribute(value = "noConsoleNoAnsi", defaultBoolean = false) final boolean noConsoleNoAnsi,
        @PluginAttribute("header") final String header,
        @PluginAttribute("footer") final String footer) {
    return newBuilder()
            .withPattern(PATTERN)
            .withConfiguration(configuration)
            .withRegexReplacement(replace)
            .withCharset(charset)
            .withAlwaysWriteExceptions(alwaysWriteExceptions)
            .withNoConsoleNoAnsi(noConsoleNoAnsi)
            .withHeader(header)
            .withFooter(footer)
            .build();
}
项目:mule-access-log    文件:CommonAccessLogPatternLayout.java   
@PluginFactory
public static Layout createLayout(@PluginElement("Replace") final RegexReplacement replace,
                                  @PluginConfiguration final Configuration configuration,
                                  @PluginAttribute(value = "charset", defaultString = "UTF-8") final Charset charset,
                                  @PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions,
                                  @PluginAttribute(value = "noConsoleNoAnsi", defaultBoolean = false) final boolean noConsoleNoAnsi,
                                  @PluginAttribute("header") final String header,
                                  @PluginAttribute("footer") final String footer) {
    return newBuilder()
            .withPattern(PATTERN)
            .withConfiguration(configuration)
            .withRegexReplacement(replace)
            .withCharset(charset)
            .withAlwaysWriteExceptions(alwaysWriteExceptions)
            .withNoConsoleNoAnsi(noConsoleNoAnsi)
            .withHeader(header)
            .withFooter(footer)
            .build();
}
项目:logging-log4j2    文件:CsvParameterLayout.java   
@PluginFactory
public static AbstractCsvLayout createLayout(
        // @formatter:off
        @PluginConfiguration final Configuration config,
        @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
        @PluginAttribute("delimiter") final Character delimiter,
        @PluginAttribute("escape") final Character escape,
        @PluginAttribute("quote") final Character quote,
        @PluginAttribute("quoteMode") final QuoteMode quoteMode,
        @PluginAttribute("nullString") final String nullString,
        @PluginAttribute("recordSeparator") final String recordSeparator,
        @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
        @PluginAttribute("header") final String header, 
        @PluginAttribute("footer") final String footer)
        // @formatter:on
{

    final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
    return new CsvParameterLayout(config, charset, csvFormat, header, footer);
}
项目:logging-log4j2    文件:CsvLogEventLayout.java   
@PluginFactory
public static CsvLogEventLayout createLayout(
        // @formatter:off
        @PluginConfiguration final Configuration config,
        @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
        @PluginAttribute("delimiter") final Character delimiter,
        @PluginAttribute("escape") final Character escape,
        @PluginAttribute("quote") final Character quote,
        @PluginAttribute("quoteMode") final QuoteMode quoteMode,
        @PluginAttribute("nullString") final String nullString,
        @PluginAttribute("recordSeparator") final String recordSeparator,
        @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
        @PluginAttribute("header") final String header,
        @PluginAttribute("footer") final String footer)
        // @formatter:on
{

    final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
    return new CsvLogEventLayout(config, charset, csvFormat, header, footer);
}
项目:logging-log4j2    文件:LoggerConfig.java   
/**
 * Factory method to create a LoggerConfig.
 *
 * @param additivity True if additive, false otherwise.
 * @param level The Level to be associated with the Logger.
 * @param loggerName The name of the Logger.
 * @param includeLocation whether location should be passed downstream
 * @param refs An array of Appender names.
 * @param properties Properties to pass to the Logger.
 * @param config The Configuration.
 * @param filter A Filter.
 * @return A new LoggerConfig.
 * @deprecated Deprecated in 2.7; use {@link #createLogger(boolean, Level, String, String, AppenderRef[], Property[], Configuration, Filter)}
 */
@Deprecated
public static LoggerConfig createLogger(final String additivity,
        // @formatter:off
        final Level level,
        @PluginAttribute("name") final String loggerName,
        final String includeLocation,
        final AppenderRef[] refs,
        final Property[] properties,
        @PluginConfiguration final Configuration config,
        final Filter filter) {
        // @formatter:on
    if (loggerName == null) {
        LOGGER.error("Loggers cannot be configured without a name");
        return null;
    }

    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    final String name = loggerName.equals(ROOT) ? Strings.EMPTY : loggerName;
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new LoggerConfig(name, appenderRefs, filter, level, additive, properties, config,
            includeLocation(includeLocation));
}
项目:logging-log4j2    文件:LoggerConfig.java   
/**
 * Factory method to create a LoggerConfig.
 *
 * @param additivity true if additive, false otherwise.
 * @param level The Level to be associated with the Logger.
 * @param loggerName The name of the Logger.
 * @param includeLocation whether location should be passed downstream
 * @param refs An array of Appender names.
 * @param properties Properties to pass to the Logger.
 * @param config The Configuration.
 * @param filter A Filter.
 * @return A new LoggerConfig.
 * @since 2.6
 */
@PluginFactory
public static LoggerConfig createLogger(
     // @formatter:off
    @PluginAttribute(value = "additivity", defaultBoolean = true) final boolean additivity,
    @PluginAttribute("level") final Level level,
    @Required(message = "Loggers cannot be configured without a name") @PluginAttribute("name") final String loggerName,
    @PluginAttribute("includeLocation") final String includeLocation,
    @PluginElement("AppenderRef") final AppenderRef[] refs,
    @PluginElement("Properties") final Property[] properties,
    @PluginConfiguration final Configuration config,
    @PluginElement("Filter") final Filter filter
    // @formatter:on
) {
    final String name = loggerName.equals(ROOT) ? Strings.EMPTY : loggerName;
    return new LoggerConfig(name, Arrays.asList(refs), filter, level, additivity, properties, config,
        includeLocation(includeLocation));
}
项目:logging-log4j2    文件:LoggerConfig.java   
@PluginFactory
public static LoggerConfig createLogger(
        // @formatter:off
        @PluginAttribute("additivity") final String additivity,
        @PluginAttribute("level") final Level level,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("AppenderRef") final AppenderRef[] refs,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filter") final Filter filter) {
        // @formatter:on
    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    final Level actualLevel = level == null ? Level.ERROR : level;
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new LoggerConfig(LogManager.ROOT_LOGGER_NAME, appenderRefs, filter, actualLevel, additive,
            properties, config, includeLocation(includeLocation));
}
项目:logging-log4j2    文件:RewriteAppender.java   
/**
 * Creates a RewriteAppender.
 * @param name The name of the Appender.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param appenderRefs An array of Appender names to call.
 * @param config The Configuration.
 * @param rewritePolicy The policy to use to modify the event.
 * @param filter A Filter to filter events.
 * @return The created RewriteAppender.
 */
@PluginFactory
public static RewriteAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginElement("AppenderRef") final AppenderRef[] appenderRefs,
        @PluginConfiguration final Configuration config,
        @PluginElement("RewritePolicy") final RewritePolicy rewritePolicy,
        @PluginElement("Filter") final Filter filter) {

    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    if (name == null) {
        LOGGER.error("No name provided for RewriteAppender");
        return null;
    }
    if (appenderRefs == null) {
        LOGGER.error("No appender references defined for RewriteAppender");
        return null;
    }
    return new RewriteAppender(name, filter, ignoreExceptions, appenderRefs, rewritePolicy, config);
}
项目:logging-log4j2    文件:DirectWriteRolloverStrategy.java   
/**
 * Creates the DirectWriteRolloverStrategy.
 *
 * @param maxFiles The maximum number of files that match the date portion of the pattern to keep.
 * @param compressionLevelStr The compression level, 0 (less) through 9 (more); applies only to ZIP files.
 * @param customActions custom actions to perform asynchronously after rollover
 * @param stopCustomActionsOnError whether to stop executing asynchronous actions if an error occurs
 * @param config The Configuration.
 * @return A DirectWriteRolloverStrategy.
 * @deprecated Since 2.9 Usage of Builder API is preferable
 */
@Deprecated
@PluginFactory
public static DirectWriteRolloverStrategy createStrategy(
        // @formatter:off
        @PluginAttribute("maxFiles") final String maxFiles,
        @PluginAttribute("compressionLevel") final String compressionLevelStr,
        @PluginElement("Actions") final Action[] customActions,
        @PluginAttribute(value = "stopCustomActionsOnError", defaultBoolean = true)
                final boolean stopCustomActionsOnError,
        @PluginConfiguration final Configuration config) {
        return newBuilder().withMaxFiles(maxFiles)
                .withCompressionLevelStr(compressionLevelStr)
                .withCustomActions(customActions)
                .withStopCustomActionsOnError(stopCustomActionsOnError)
                .withConfig(config)
                .build();
        // @formatter:on
}
项目:logging-log4j2    文件:CronTriggeringPolicy.java   
/**
 * Creates a ScheduledTriggeringPolicy.
 * 
 * @param configuration
 *            the Configuration.
 * @param evaluateOnStartup
 *            check if the file should be rolled over immediately.
 * @param schedule
 *            the cron expression.
 * @return a ScheduledTriggeringPolicy.
 */
@PluginFactory
public static CronTriggeringPolicy createPolicy(@PluginConfiguration final Configuration configuration,
        @PluginAttribute("evaluateOnStartup") final String evaluateOnStartup,
        @PluginAttribute("schedule") final String schedule) {
    CronExpression cronExpression;
    final boolean checkOnStartup = Boolean.parseBoolean(evaluateOnStartup);
    if (schedule == null) {
        LOGGER.info("No schedule specified, defaulting to Daily");
        cronExpression = getSchedule(defaultSchedule);
    } else {
        cronExpression = getSchedule(schedule);
        if (cronExpression == null) {
            LOGGER.error("Invalid expression specified. Defaulting to Daily");
            cronExpression = getSchedule(defaultSchedule);
        }
    }
    return new CronTriggeringPolicy(cronExpression, checkOnStartup, configuration);
}
项目:logging-log4j2    文件:DefaultRolloverStrategy.java   
/**
 * Creates the DefaultRolloverStrategy.
 *
 * @param max The maximum number of files to keep.
 * @param min The minimum number of files to keep.
 * @param fileIndex If set to "max" (the default), files with a higher index will be newer than files with a smaller
 *            index. If set to "min", file renaming and the counter will follow the Fixed Window strategy.
 * @param compressionLevelStr The compression level, 0 (less) through 9 (more); applies only to ZIP files.
 * @param customActions custom actions to perform asynchronously after rollover
 * @param stopCustomActionsOnError whether to stop executing asynchronous actions if an error occurs
 * @param config The Configuration.
 * @return A DefaultRolloverStrategy.
 * @deprecated Since 2.9 Usage of Builder API is preferable
 */
@PluginFactory
@Deprecated
public static DefaultRolloverStrategy createStrategy(
        // @formatter:off
        @PluginAttribute("max") final String max,
        @PluginAttribute("min") final String min,
        @PluginAttribute("fileIndex") final String fileIndex,
        @PluginAttribute("compressionLevel") final String compressionLevelStr,
        @PluginElement("Actions") final Action[] customActions,
        @PluginAttribute(value = "stopCustomActionsOnError", defaultBoolean = true)
                final boolean stopCustomActionsOnError,
        @PluginConfiguration final Configuration config) {
    return DefaultRolloverStrategy.newBuilder()
                .withMin(min)
                .withMax(max)
                .withFileIndex(fileIndex)
                .withCompressionLevelStr(compressionLevelStr)
                .withCustomActions(customActions)
                .withStopCustomActionsOnError(stopCustomActionsOnError)
                .withConfig(config)
            .build();
        // @formatter:on
}
项目:logging-log4j2    文件:ScriptFilter.java   
/**
 * Creates the ScriptFilter.
 * @param script The script to run. The script must return a boolean value. Either script or scriptFile must be 
 *      provided.
 * @param match The action to take if a match occurs.
 * @param mismatch The action to take if no match occurs.
 * @param configuration the configuration 
 * @return A ScriptFilter.
 */
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
@PluginFactory
public static ScriptFilter createFilter(
        @PluginElement("Script") final AbstractScript script,
        @PluginAttribute("onMatch") final Result match,
        @PluginAttribute("onMismatch") final Result mismatch,
        @PluginConfiguration final Configuration configuration) {

    if (script == null) {
        LOGGER.error("A Script, ScriptFile or ScriptRef element must be provided for this ScriptFilter");
        return null;
    }
    if (script instanceof ScriptRef) {
        if (configuration.getScriptManager().getScript(script.getName()) == null) {
            logger.error("No script with name {} has been declared.", script.getName());
            return null;
        }
    }

    return new ScriptFilter(script, configuration, match, mismatch);
}
项目:logging-log4j2    文件:AsyncLoggerConfig.java   
@PluginFactory
public static LoggerConfig createLogger(
        @PluginAttribute("additivity") final String additivity,
        @PluginAttribute("level") final String levelName,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("AppenderRef") final AppenderRef[] refs,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filter") final Filter filter) {
    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    Level level;
    try {
        level = Level.toLevel(levelName, Level.ERROR);
    } catch (final Exception ex) {
        LOGGER.error(
                "Invalid Log level specified: {}. Defaulting to Error",
                levelName);
        level = Level.ERROR;
    }
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new AsyncLoggerConfig(LogManager.ROOT_LOGGER_NAME,
            appenderRefs, filter, level, additive, properties, config,
            AsyncLoggerConfig.includeLocation(includeLocation));
}
项目:logging-log4j2    文件:PatternLayout.java   
/**
 * Creates a pattern layout.
 *
 * @param pattern
 *        The pattern. If not specified, defaults to DEFAULT_CONVERSION_PATTERN.
 * @param patternSelector
 *        Allows different patterns to be used based on some selection criteria.
 * @param config
 *        The Configuration. Some Converters require access to the Interpolator.
 * @param replace
 *        A Regex replacement String.
 * @param charset
 *        The character set. The platform default is used if not specified.
 * @param alwaysWriteExceptions
 *        If {@code "true"} (default) exceptions are always written even if the pattern contains no exception tokens.
 * @param noConsoleNoAnsi
 *        If {@code "true"} (default is false) and {@link System#console()} is null, do not output ANSI escape codes
 * @param headerPattern
 *        The footer to place at the top of the document, once.
 * @param footerPattern
 *        The footer to place at the bottom of the document, once.
 * @return The PatternLayout.
 * @deprecated Use {@link #newBuilder()} instead. This will be private in a future version.
 */
@PluginFactory
@Deprecated
public static PatternLayout createLayout(
        @PluginAttribute(value = "pattern", defaultString = DEFAULT_CONVERSION_PATTERN) final String pattern,
        @PluginElement("PatternSelector") final PatternSelector patternSelector,
        @PluginConfiguration final Configuration config,
        @PluginElement("Replace") final RegexReplacement replace,
        // LOG4J2-783 use platform default by default, so do not specify defaultString for charset
        @PluginAttribute(value = "charset") final Charset charset,
        @PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions,
        @PluginAttribute(value = "noConsoleNoAnsi") final boolean noConsoleNoAnsi,
        @PluginAttribute("header") final String headerPattern,
        @PluginAttribute("footer") final String footerPattern) {
    return newBuilder()
        .withPattern(pattern)
        .withPatternSelector(patternSelector)
        .withConfiguration(config)
        .withRegexReplacement(replace)
        .withCharset(charset)
        .withAlwaysWriteExceptions(alwaysWriteExceptions)
        .withNoConsoleNoAnsi(noConsoleNoAnsi)
        .withHeader(headerPattern)
        .withFooter(footerPattern)
        .build();
}
项目:zebra    文件:ZebraRolloverStrategy.java   
/**
 * Create the DefaultRolloverStrategy.
 * @param max The maximum number of files to keep.
 * @param min The minimum number of files to keep.
 * @param fileIndex If set to "max" (the default), files with a higher index will be newer than files with a
 * smaller index. If set to "min", file renaming and the counter will follow the Fixed Window strategy.
 * @param compressionLevelStr The compression level, 0 (less) through 9 (more); applies only to ZIP files.
 * @param config The Configuration.
 * @return A DefaultRolloverStrategy.
 */
@PluginFactory
public static ZebraRolloverStrategy createStrategy(
        @PluginAttribute("max") final String max,
        @PluginAttribute("min") final String min,
        @PluginAttribute("fileIndex") final String fileIndex,
        @PluginAttribute("compressionLevel") final String compressionLevelStr,
        @PluginConfiguration final Configuration config) {
    final boolean useMax = fileIndex == null ? true : fileIndex.equalsIgnoreCase("max");
    int minIndex = MIN_WINDOW_SIZE;
    if (min != null) {
        minIndex = Integer.parseInt(min);
        if (minIndex < 1) {
            LOGGER.error("Minimum window size too small. Limited to " + MIN_WINDOW_SIZE);
            minIndex = MIN_WINDOW_SIZE;
        }
    }
    int maxIndex = DEFAULT_WINDOW_SIZE;
    if (max != null) {
        maxIndex = Integer.parseInt(max);
        if (maxIndex < minIndex) {
            maxIndex = minIndex < DEFAULT_WINDOW_SIZE ? DEFAULT_WINDOW_SIZE : minIndex;
            LOGGER.error("Maximum window size must be greater than the minimum windows size. Set to " + maxIndex);
        }
    }
    final int compressionLevel = Integers.parseInt(compressionLevelStr, Deflater.DEFAULT_COMPRESSION);
    return new ZebraRolloverStrategy(minIndex, maxIndex, useMax, compressionLevel, config.getStrSubstitutor());
}
项目:log4j2-simplejson    文件:SimpleJSONLayout.java   
@PluginFactory
public static SimpleJSONLayout createLayout( //
        @PluginConfiguration final Configuration config, //
        @PluginAttribute(value = "locationInfo", defaultBoolean = false) final boolean locationInfo, //
        @PluginAttribute(value = "properties", defaultBoolean = true) final boolean properties, //
        @PluginAttribute(value = "complete", defaultBoolean = false) final boolean complete, //
        @PluginAttribute(value = "eventEol", defaultBoolean = true) final boolean eventEol, //
        @PluginAttribute(value = "header", defaultString = DEFAULT_HEADER) final String headerPattern, //
        @PluginAttribute(value = "footer", defaultString = DEFAULT_FOOTER) final String footerPattern, //
        @PluginAttribute(value = "charset", defaultString = "US-ASCII") final Charset charset, //
        @PluginElement("AdditionalField") final KeyValuePair[] additionalFields) {
    return new SimpleJSONLayout(config, locationInfo, properties, complete, eventEol, headerPattern,
            footerPattern, charset, additionalFields);
}
项目:log4j-systemd-journal-appender    文件:SystemdJournalAppender.java   
@PluginFactory
public static SystemdJournalAppender createAppender(@PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignoreExceptionsString,
        @PluginAttribute("logSource") final String logSourceString,
        @PluginAttribute("logStacktrace") final String logStacktraceString,
        @PluginAttribute("logLoggerName") final String logLoggerNameString,
        @PluginAttribute("logAppenderName") final String logAppenderNameString,
        @PluginAttribute("logThreadName") final String logThreadNameString,
        @PluginAttribute("logThreadContext") final String logThreadContextString,
        @PluginAttribute("threadContextPrefix") final String threadContextPrefix,
        @PluginAttribute("syslogIdentifier") final String syslogIdentifier,
        @PluginElement("Layout") final Layout layout,
        @PluginElement("Filter") final Filter filter,
        @PluginConfiguration final Configuration config) {
    final boolean ignoreExceptions = Booleans.parseBoolean(ignoreExceptionsString, true);
    final boolean logSource = Booleans.parseBoolean(logSourceString, false);
    final boolean logStacktrace = Booleans.parseBoolean(logStacktraceString, true);
    final boolean logThreadName = Booleans.parseBoolean(logThreadNameString, true);
    final boolean logLoggerName = Booleans.parseBoolean(logLoggerNameString, true);
    final boolean logAppenderName = Booleans.parseBoolean(logAppenderNameString, true);
    final boolean logThreadContext = Booleans.parseBoolean(logThreadContextString, true);

    if (name == null) {
        LOGGER.error("No name provided for SystemdJournalAppender");
        return null;
    }

    SystemdJournalLibrary journalLibrary = (SystemdJournalLibrary) Native.loadLibrary("systemd",
            SystemdJournalLibrary.class);

    return new SystemdJournalAppender(name, filter, layout, ignoreExceptions, journalLibrary, logSource, logStacktrace,
            logThreadName, logLoggerName, logAppenderName, logThreadContext, threadContextPrefix, syslogIdentifier);
}
项目:log4j2    文件:LoggerConfig.java   
/**
 * Factory method to create a LoggerConfig.
 *
 * @param additivity True if additive, false otherwise.
 * @param levelName The Level to be associated with the Logger.
 * @param loggerName The name of the Logger.
 * @param includeLocation whether location should be passed downstream
 * @param refs An array of Appender names.
 * @param properties Properties to pass to the Logger.
 * @param config The Configuration.
 * @param filter A Filter.
 * @return A new LoggerConfig.
 */
@PluginFactory
public static LoggerConfig createLogger(
        @PluginAttribute("additivity") final String additivity,
        @PluginAttribute("level") final String levelName,
        @PluginAttribute("name") final String loggerName,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("AppenderRef") final AppenderRef[] refs,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filters") final Filter filter) {
    if (loggerName == null) {
        LOGGER.error("Loggers cannot be configured without a name");
        return null;
    }

    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    Level level;
    try {
        level = Level.toLevel(levelName, Level.ERROR);
    } catch (final Exception ex) {
        LOGGER.error(
                "Invalid Log level specified: {}. Defaulting to Error",
                levelName);
        level = Level.ERROR;
    }
    final String name = loggerName.equals("root") ? "" : loggerName;
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new LoggerConfig(name, appenderRefs, filter, level, additive,
            properties, config, includeLocation(includeLocation));
}
项目:log4j2    文件:AsyncAppender.java   
/**
 * Create an AsyncAppender.
 * @param appenderRefs The Appenders to reference.
 * @param errorRef An optional Appender to write to if the queue is full or other errors occur.
 * @param blocking True if the Appender should wait when the queue is full. The default is true.
 * @param size The size of the event queue. The default is 128.
 * @param name The name of the Appender.
 * @param includeLocation whether to include location information. The default is false.
 * @param filter The Filter or null.
 * @param config The Configuration.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @return The AsyncAppender.
 */
@PluginFactory
public static AsyncAppender createAppender(@PluginElement("AppenderRef") final AppenderRef[] appenderRefs,
        @PluginAttribute("errorRef") @PluginAliases("error-ref") final String errorRef,
        @PluginAttribute("blocking") final String blocking, 
        @PluginAttribute("bufferSize") final String size,
        @PluginAttribute("name") final String name,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("Filter") final Filter filter, 
        @PluginConfiguration final Configuration config,
        @PluginAttribute("ignoreExceptions") final String ignore) {
    if (name == null) {
        LOGGER.error("No name provided for AsyncAppender");
        return null;
    }
    if (appenderRefs == null) {
        LOGGER.error("No appender references provided to AsyncAppender {}", name);
    }

    final boolean isBlocking = Booleans.parseBoolean(blocking, true);
    final int queueSize = AbstractAppender.parseInt(size, DEFAULT_QUEUE_SIZE);
    final boolean isIncludeLocation = Boolean.parseBoolean(includeLocation);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    return new AsyncAppender(name, filter, appenderRefs, errorRef,
            queueSize, isBlocking, ignoreExceptions, config, isIncludeLocation);
}
项目:log4j2    文件:PropertiesRewritePolicy.java   
/**
 * The factory method to create the PropertiesRewritePolicy.
 * @param config The Configuration.
 * @param props key/value pairs for the new keys and values.
 * @return The PropertiesRewritePolicy.
 */
@PluginFactory
public static PropertiesRewritePolicy createPolicy(@PluginConfiguration final Configuration config,
                                            @PluginElement("Properties") final Property[] props) {
    if (props == null || props.length == 0) {
        LOGGER.error("Properties must be specified for the PropertiesRewritePolicy");
        return null;
    }
    final List<Property> properties = Arrays.asList(props);
    return new PropertiesRewritePolicy(config, properties);
}
项目:log4j2    文件:FailoverAppender.java   
/**
 * Create a Failover Appender.
 * @param name The name of the Appender (required).
 * @param primary The name of the primary Appender (required).
 * @param failovers The name of one or more Appenders to fail over to (at least one is required).
 * @param retryIntervalString The retry intervalMillis.
 * @param config The current Configuration (passed by the Configuration when the appender is created).
 * @param filter A Filter (optional).
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @return The FailoverAppender that was created.
 */
@PluginFactory
public static FailoverAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("primary") final String primary,
        @PluginElement("Failovers") final String[] failovers,
        @PluginAttribute("retryInterval") final String retryIntervalString,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filters") final Filter filter,
        @PluginAttribute("ignoreExceptions") final String ignore) {
    if (name == null) {
        LOGGER.error("A name for the Appender must be specified");
        return null;
    }
    if (primary == null) {
        LOGGER.error("A primary Appender must be specified");
        return null;
    }
    if (failovers == null || failovers.length == 0) {
        LOGGER.error("At least one failover Appender must be specified");
        return null;
    }

    final int seconds = parseInt(retryIntervalString, DEFAULT_INTERVAL_SECONDS);
    int retryIntervalMillis;
    if (seconds >= 0) {
        retryIntervalMillis = seconds * Constants.MILLIS_IN_SECONDS;
    } else {
        LOGGER.warn("Interval " + retryIntervalString + " is less than zero. Using default");
        retryIntervalMillis = DEFAULT_INTERVAL_SECONDS * Constants.MILLIS_IN_SECONDS;
    }

    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    return new FailoverAppender(name, filter, primary, failovers, retryIntervalMillis, config, ignoreExceptions);
}
项目:log4j2    文件:DefaultRolloverStrategy.java   
/**
 * Create the DefaultRolloverStrategy.
 * @param max The maximum number of files to keep.
 * @param min The minimum number of files to keep.
 * @param fileIndex If set to "max" (the default), files with a higher index will be newer than files with a
 * smaller index. If set to "min", file renaming and the counter will follow the Fixed Window strategy.
 * @param compressionLevelStr The compression level, 0 (less) through 9 (more); applies only to ZIP files.
 * @param config The Configuration.
 * @return A DefaultRolloverStrategy.
 */
@PluginFactory
public static DefaultRolloverStrategy createStrategy(
        @PluginAttribute("max") final String max,
        @PluginAttribute("min") final String min,
        @PluginAttribute("fileIndex") final String fileIndex,
        @PluginAttribute("compressionLevel") final String compressionLevelStr,
        @PluginConfiguration final Configuration config) {
    final boolean useMax = fileIndex == null ? true : fileIndex.equalsIgnoreCase("max");
    int minIndex;
    if (min != null) {
        minIndex = Integer.parseInt(min);
        if (minIndex < 1) {
            LOGGER.error("Minimum window size too small. Limited to " + MIN_WINDOW_SIZE);
            minIndex = MIN_WINDOW_SIZE;
        }
    } else {
        minIndex = MIN_WINDOW_SIZE;
    }
    int maxIndex;
    if (max != null) {
        maxIndex = Integer.parseInt(max);
        if (maxIndex < minIndex) {
            maxIndex = minIndex < DEFAULT_WINDOW_SIZE ? DEFAULT_WINDOW_SIZE : minIndex;
            LOGGER.error("Maximum window size must be greater than the minimum windows size. Set to " + maxIndex);
        }
    } else {
        maxIndex = DEFAULT_WINDOW_SIZE;
    }
    final int compressionLevel = Integers.parseInt(compressionLevelStr, Deflater.DEFAULT_COMPRESSION);
    return new DefaultRolloverStrategy(minIndex, maxIndex, useMax, compressionLevel, config.getStrSubstitutor());
}
项目:log4j2    文件:AsyncLoggerConfig.java   
/**
 * Factory method to create a LoggerConfig.
 *
 * @param additivity True if additive, false otherwise.
 * @param levelName The Level to be associated with the Logger.
 * @param loggerName The name of the Logger.
 * @param includeLocation "true" if location should be passed downstream
 * @param refs An array of Appender names.
 * @param properties Properties to pass to the Logger.
 * @param config The Configuration.
 * @param filter A Filter.
 * @return A new LoggerConfig.
 */
@PluginFactory
public static LoggerConfig createLogger(
        @PluginAttribute("additivity") final String additivity,
        @PluginAttribute("level") final String levelName,
        @PluginAttribute("name") final String loggerName,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("AppenderRef") final AppenderRef[] refs,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filters") final Filter filter) {
    if (loggerName == null) {
        LOGGER.error("Loggers cannot be configured without a name");
        return null;
    }

    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    Level level;
    try {
        level = Level.toLevel(levelName, Level.ERROR);
    } catch (final Exception ex) {
        LOGGER.error(
                "Invalid Log level specified: {}. Defaulting to Error",
                levelName);
        level = Level.ERROR;
    }
    final String name = loggerName.equals("root") ? "" : loggerName;
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new AsyncLoggerConfig(name, appenderRefs, filter, level,
            additive, properties, config, includeLocation(includeLocation));
}
项目:log4j2    文件:RFC5424Layout.java   
/**
 * Create the RFC 5424 Layout.
 *
 * @param facility         The Facility is used to try to classify the message.
 * @param id               The default structured data id to use when formatting according to RFC 5424.
 * @param ein              The IANA enterprise number.
 * @param includeMDC       Indicates whether data from the ThreadContextMap will be included in the RFC 5424 Syslog
 *                         record. Defaults to "true:.
 * @param mdcId            The id to use for the MDC Structured Data Element.
 * @param mdcPrefix        The prefix to add to MDC key names.
 * @param eventPrefix      The prefix to add to event key names.
 * @param includeNL        If true, a newline will be appended to the end of the syslog record. The default is false.
 * @param escapeNL         String that should be used to replace newlines within the message text.
 * @param appName          The value to use as the APP-NAME in the RFC 5424 syslog record.
 * @param msgId            The default value to be used in the MSGID field of RFC 5424 syslog records.
 * @param excludes         A comma separated list of MDC keys that should be excluded from the LogEvent.
 * @param includes         A comma separated list of MDC keys that should be included in the FlumeEvent.
 * @param required         A comma separated list of MDC keys that must be present in the MDC.
 * @param exceptionPattern The pattern for formatting exceptions.
 * @param useTLSMessageFormat If true the message will be formatted according to RFC 5425.
 * @param loggerFields     Container for the KeyValuePairs containing the patterns
 * @param config           The Configuration. Some Converters require access to the Interpolator.
 * @return An RFC5424Layout.
 */
@PluginFactory
public static RFC5424Layout createLayout(
        @PluginAttribute("facility") final String facility,
        @PluginAttribute("id") final String id,
        @PluginAttribute("enterpriseNumber") final String ein,
        @PluginAttribute("includeMDC") final String includeMDC,
        @PluginAttribute("mdcId") String mdcId,
        @PluginAttribute("mdcPrefix") final String mdcPrefix,
        @PluginAttribute("eventPrefix") final String eventPrefix,
        @PluginAttribute("newLine") final String includeNL,
        @PluginAttribute("newLineEscape") final String escapeNL,
        @PluginAttribute("appName") final String appName,
        @PluginAttribute("messageId") final String msgId,
        @PluginAttribute("mdcExcludes") final String excludes,
        @PluginAttribute("mdcIncludes") String includes,
        @PluginAttribute("mdcRequired") final String required,
        @PluginAttribute("exceptionPattern") final String exceptionPattern,
        @PluginAttribute("useTLSMessageFormat") final String useTLSMessageFormat, // RFC 5425
        @PluginElement("LoggerFields") final LoggerFields[] loggerFields,
        @PluginConfiguration final Configuration config) {
    final Charset charset = Charsets.UTF_8;
    if (includes != null && excludes != null) {
        LOGGER.error("mdcIncludes and mdcExcludes are mutually exclusive. Includes wil be ignored");
        includes = null;
    }
    final Facility f = Facility.toFacility(facility, Facility.LOCAL0);
    final int enterpriseNumber = Integers.parseInt(ein, DEFAULT_ENTERPRISE_NUMBER);
    final boolean isMdc = Booleans.parseBoolean(includeMDC, true);
    final boolean includeNewLine = Boolean.parseBoolean(includeNL);
    final boolean useTlsMessageFormat = Booleans.parseBoolean(useTLSMessageFormat, false);
    if (mdcId == null) {
        mdcId = DEFAULT_MDCID;
    }

    return new RFC5424Layout(config, f, id, enterpriseNumber, isMdc, includeNewLine, escapeNL, mdcId, mdcPrefix,
            eventPrefix, appName, msgId, excludes, includes, required, charset, exceptionPattern,
            useTlsMessageFormat, loggerFields);
}
项目:log4j2    文件:PatternLayout.java   
/**
 * Create a pattern layout.
 *
 * @param pattern The pattern. If not specified, defaults to DEFAULT_CONVERSION_PATTERN.
 * @param config The Configuration. Some Converters require access to the Interpolator.
 * @param replace A Regex replacement String.
 * @param charsetName The character set.
 * @param always If {@code "true"} (default) exceptions are always written even if the pattern contains no exception
 *               tokens.
 * @return The PatternLayout.
 */
@PluginFactory
public static PatternLayout createLayout(
        @PluginAttribute("pattern") final String pattern,
        @PluginConfiguration final Configuration config,
        @PluginElement("Replace") final RegexReplacement replace,
        @PluginAttribute("charset") final String charsetName,
        @PluginAttribute("alwaysWriteExceptions") final String always) {
    final Charset charset = Charsets.getSupportedCharset(charsetName);
    final boolean alwaysWriteExceptions = Booleans.parseBoolean(always, true);
    return new PatternLayout(
            config, replace, pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern, charset, alwaysWriteExceptions
    );
}
项目:logstash-gelf    文件:GelfDynamicMdcLogFields.java   
@PluginFactory
public static GelfDynamicMdcLogFields createField(@PluginConfiguration final Configuration config,
        @PluginAttribute("regex") String regex) {

    if (Strings.isEmpty(regex)) {
        LOGGER.error("The regex is empty");
        return null;
    }

    return new GelfDynamicMdcLogFields(regex);
}
项目:logstash-gelf    文件:GelfLogField.java   
@PluginFactory
public static GelfLogField createField(@PluginConfiguration final Configuration config,
        @PluginAttribute("name") String name, @PluginAttribute("literal") String literalValue,
        @PluginAttribute("mdc") String mdc, @PluginAttribute("pattern") String pattern) {

    final boolean isPattern = Strings.isNotEmpty(pattern);
    final boolean isLiteralValue = Strings.isNotEmpty(literalValue);
    final boolean isMDC = Strings.isNotEmpty(mdc);

    if (Strings.isEmpty(name)) {
        LOGGER.error("The name is empty");
        return null;
    }

    if ((isPattern && isLiteralValue) || (isPattern && isMDC) || (isLiteralValue && isMDC)) {
        LOGGER.error("The pattern, literal, and mdc attributes are mutually exclusive.");
        return null;
    }

    if (isPattern) {

        PatternLayout patternLayout = newBuilder().withPattern(pattern).withConfiguration(config)
                .withNoConsoleNoAnsi(false).withAlwaysWriteExceptions(false).build();

        return new GelfLogField(name, null, null, patternLayout);
    }

    return new GelfLogField(name, literalValue, mdc, null);
}
项目:logging-log4j2    文件:ScriptRef.java   
@PluginFactory
public static ScriptRef createReference(
        // @formatter:off
        @PluginAttribute("ref") final String name,
        @PluginConfiguration final Configuration configuration) {
        // @formatter:on
    if (name == null) {
        LOGGER.error("No script name provided");
        return null;
    }
    return new ScriptRef(name, configuration.getScriptManager());

}
项目:logging-log4j2    文件:PropertiesPlugin.java   
/**
 * Creates the Properties component.
 * @param properties An array of Property elements.
 * @param config The Configuration.
 * @return An Interpolator that includes the configuration properties.
 */
@PluginFactory
public static StrLookup configureSubstitutor(@PluginElement("Properties") final Property[] properties,
                                             @PluginConfiguration final Configuration config) {
    if (properties == null) {
        return new Interpolator(config.getProperties());
    }
    final Map<String, String> map = new HashMap<>(config.getProperties());

    for (final Property prop : properties) {
        map.put(prop.getName(), prop.getValue());
    }

    return new Interpolator(new MapLookup(map), config.getPluginPackages());
}
项目:logging-log4j2    文件:PropertiesRewritePolicy.java   
/**
 * Creates a PropertiesRewritePolicy.
 * @param config The Configuration.
 * @param props key/value pairs for the new keys and values.
 * @return The PropertiesRewritePolicy.
 */
@PluginFactory
public static PropertiesRewritePolicy createPolicy(@PluginConfiguration final Configuration config,
                                            @PluginElement("Properties") final Property[] props) {
    if (props == null || props.length == 0) {
        LOGGER.error("Properties must be specified for the PropertiesRewritePolicy");
        return null;
    }
    final List<Property> properties = Arrays.asList(props);
    return new PropertiesRewritePolicy(config, properties);
}
项目:logging-log4j2    文件:FailoverAppender.java   
/**
 * Create a Failover Appender.
 * @param name The name of the Appender (required).
 * @param primary The name of the primary Appender (required).
 * @param failovers The name of one or more Appenders to fail over to (at least one is required).
 * @param retryIntervalSeconds The retry interval in seconds.
 * @param config The current Configuration (passed by the Configuration when the appender is created).
 * @param filter A Filter (optional).
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @return The FailoverAppender that was created.
 */
@PluginFactory
public static FailoverAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("primary") final String primary,
        @PluginElement("Failovers") final String[] failovers,
        @PluginAliases("retryInterval") // deprecated
        @PluginAttribute("retryIntervalSeconds") final String retryIntervalSeconds,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filter") final Filter filter,
        @PluginAttribute("ignoreExceptions") final String ignore) {
    if (name == null) {
        LOGGER.error("A name for the Appender must be specified");
        return null;
    }
    if (primary == null) {
        LOGGER.error("A primary Appender must be specified");
        return null;
    }
    if (failovers == null || failovers.length == 0) {
        LOGGER.error("At least one failover Appender must be specified");
        return null;
    }

    final int seconds = parseInt(retryIntervalSeconds, DEFAULT_INTERVAL_SECONDS);
    int retryIntervalMillis;
    if (seconds >= 0) {
        retryIntervalMillis = seconds * Constants.MILLIS_IN_SECONDS;
    } else {
        LOGGER.warn("Interval " + retryIntervalSeconds + " is less than zero. Using default");
        retryIntervalMillis = DEFAULT_INTERVAL_SECONDS * Constants.MILLIS_IN_SECONDS;
    }

    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    return new FailoverAppender(name, filter, primary, failovers, retryIntervalMillis, config, ignoreExceptions);
}
项目:logging-log4j2    文件:AsyncLoggerConfig.java   
/**
 * Factory method to create a LoggerConfig.
 *
 * @param additivity True if additive, false otherwise.
 * @param levelName The Level to be associated with the Logger.
 * @param loggerName The name of the Logger.
 * @param includeLocation "true" if location should be passed downstream
 * @param refs An array of Appender names.
 * @param properties Properties to pass to the Logger.
 * @param config The Configuration.
 * @param filter A Filter.
 * @return A new LoggerConfig.
 */
@PluginFactory
public static LoggerConfig createLogger(
        @PluginAttribute("additivity") final String additivity,
        @PluginAttribute("level") final String levelName,
        @PluginAttribute("name") final String loggerName,
        @PluginAttribute("includeLocation") final String includeLocation,
        @PluginElement("AppenderRef") final AppenderRef[] refs,
        @PluginElement("Properties") final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement("Filter") final Filter filter) {
    if (loggerName == null) {
        LOGGER.error("Loggers cannot be configured without a name");
        return null;
    }

    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    Level level;
    try {
        level = Level.toLevel(levelName, Level.ERROR);
    } catch (final Exception ex) {
        LOGGER.error(
                "Invalid Log level specified: {}. Defaulting to Error",
                levelName);
        level = Level.ERROR;
    }
    final String name = loggerName.equals(LoggerConfig.ROOT) ? Strings.EMPTY : loggerName;
    final boolean additive = Booleans.parseBoolean(additivity, true);

    return new AsyncLoggerConfig(name, appenderRefs, filter, level,
            additive, properties, config, includeLocation(includeLocation));
}
项目:logging-log4j2    文件:Rfc5424Layout.java   
/**
 * Create the RFC 5424 Layout.
 *
 * @param facility The Facility is used to try to classify the message.
 * @param id The default structured data id to use when formatting according to RFC 5424.
 * @param enterpriseNumber The IANA enterprise number.
 * @param includeMDC Indicates whether data from the ThreadContextMap will be included in the RFC 5424 Syslog
 *            record. Defaults to "true:.
 * @param mdcId The id to use for the MDC Structured Data Element.
 * @param mdcPrefix The prefix to add to MDC key names.
 * @param eventPrefix The prefix to add to event key names.
 * @param newLine If true, a newline will be appended to the end of the syslog record. The default is false.
 * @param escapeNL String that should be used to replace newlines within the message text.
 * @param appName The value to use as the APP-NAME in the RFC 5424 syslog record.
 * @param msgId The default value to be used in the MSGID field of RFC 5424 syslog records.
 * @param excludes A comma separated list of MDC keys that should be excluded from the LogEvent.
 * @param includes A comma separated list of MDC keys that should be included in the FlumeEvent.
 * @param required A comma separated list of MDC keys that must be present in the MDC.
 * @param exceptionPattern The pattern for formatting exceptions.
 * @param useTlsMessageFormat If true the message will be formatted according to RFC 5425.
 * @param loggerFields Container for the KeyValuePairs containing the patterns
 * @param config The Configuration. Some Converters require access to the Interpolator.
 * @return An Rfc5424Layout.
 */
@PluginFactory
public static Rfc5424Layout createLayout(
        // @formatter:off
        @PluginAttribute(value = "facility", defaultString = "LOCAL0") final Facility facility,
        @PluginAttribute("id") final String id,
        @PluginAttribute(value = "enterpriseNumber", defaultInt = DEFAULT_ENTERPRISE_NUMBER)
        final int enterpriseNumber,
        @PluginAttribute(value = "includeMDC", defaultBoolean = true) final boolean includeMDC,
        @PluginAttribute(value = "mdcId", defaultString = DEFAULT_MDCID) final String mdcId,
        @PluginAttribute("mdcPrefix") final String mdcPrefix,
        @PluginAttribute("eventPrefix") final String eventPrefix,
        @PluginAttribute(value = "newLine") final boolean newLine,
        @PluginAttribute("newLineEscape") final String escapeNL,
        @PluginAttribute("appName") final String appName,
        @PluginAttribute("messageId") final String msgId,
        @PluginAttribute("mdcExcludes") final String excludes,
        @PluginAttribute("mdcIncludes") String includes,
        @PluginAttribute("mdcRequired") final String required,
        @PluginAttribute("exceptionPattern") final String exceptionPattern,
        // RFC 5425
        @PluginAttribute(value = "useTlsMessageFormat") final boolean useTlsMessageFormat,
        @PluginElement("LoggerFields") final LoggerFields[] loggerFields,
        @PluginConfiguration final Configuration config) {
    // @formatter:on
    if (includes != null && excludes != null) {
        LOGGER.error("mdcIncludes and mdcExcludes are mutually exclusive. Includes wil be ignored");
        includes = null;
    }

    return new Rfc5424Layout(config, facility, id, enterpriseNumber, includeMDC, newLine, escapeNL, mdcId,
            mdcPrefix, eventPrefix, appName, msgId, excludes, includes, required, StandardCharsets.UTF_8,
            exceptionPattern, useTlsMessageFormat, loggerFields);
}
项目:cf-java-logging-support    文件:JsonPatternLayout.java   
@PluginFactory
public static JsonPatternLayout createLayout(@PluginAttribute(value = "charset") final Charset charset,
                                             @PluginConfiguration final Configuration config) {
    return new Builder().withCharset(charset).withConfiguration(config).build();
}
项目:log4j2    文件:RollingFileAppender.java   
/**
 * Create a RollingFileAppender.
 * @param fileName The name of the file that is actively written to. (required).
 * @param filePattern The pattern of the file name to use on rollover. (required).
 * @param append If true, events are appended to the file. If false, the file
 * is overwritten when opened. Defaults to "true"
 * @param name The name of the Appender (required).
 * @param bufferedIO When true, I/O will be buffered. Defaults to "true".
 * @param immediateFlush When true, events are immediately flushed. Defaults to "true".
 * @param policy The triggering policy. (required).
 * @param strategy The rollover strategy. Defaults to DefaultRolloverStrategy.
 * @param layout The layout to use (defaults to the default PatternLayout).
 * @param filter The Filter or null.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param advertise "true" if the appender configuration should be advertised, "false" otherwise.
 * @param advertiseURI The advertised URI which can be used to retrieve the file contents.
 * @param config The Configuration.
 * @return A RollingFileAppender.
 */
@PluginFactory
public static RollingFileAppender createAppender(
        @PluginAttribute("fileName") final String fileName,
        @PluginAttribute("filePattern") final String filePattern,
        @PluginAttribute("append") final String append,
        @PluginAttribute("name") final String name,
        @PluginAttribute("bufferedIO") final String bufferedIO,
        @PluginAttribute("immediateFlush") final String immediateFlush,
        @PluginElement("Policy") final TriggeringPolicy policy,
        @PluginElement("Strategy") RolloverStrategy strategy,
        @PluginElement("Layout") Layout<? extends Serializable> layout,
        @PluginElement("Filter") final Filter filter,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginAttribute("advertise") final String advertise,
        @PluginAttribute("advertiseURI") final String advertiseURI,
        @PluginConfiguration final Configuration config) {

    final boolean isAppend = Booleans.parseBoolean(append, true);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final boolean isBuffered = Booleans.parseBoolean(bufferedIO, true);
    final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
    final boolean isAdvertise = Boolean.parseBoolean(advertise);
    if (name == null) {
        LOGGER.error("No name provided for FileAppender");
        return null;
    }

    if (fileName == null) {
        LOGGER.error("No filename was provided for FileAppender with name "  + name);
        return null;
    }

    if (filePattern == null) {
        LOGGER.error("No filename pattern provided for FileAppender with name "  + name);
        return null;
    }

    if (policy == null) {
        LOGGER.error("A TriggeringPolicy must be provided");
        return null;
    }

    if (strategy == null) {
        strategy = DefaultRolloverStrategy.createStrategy(null, null, null,
                String.valueOf(Deflater.DEFAULT_COMPRESSION), config);
    }

    if (layout == null) {
        layout = PatternLayout.createLayout(null, null, null, null, null);
    }

    final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, isAppend,
        isBuffered, policy, strategy, advertiseURI, layout);
    if (manager == null) {
        return null;
    }

    return new RollingFileAppender(name, layout, filter, manager, fileName, filePattern,
            ignoreExceptions, isFlush, isAdvertise ? config.getAdvertiser() : null);
}