Java 类org.apache.logging.log4j.core.util.Booleans 实例源码

项目:jline-log4j2-appender    文件:JLineConsoleAppender.java   
@PluginFactory
public static JLineConsoleAppender createAppender(@PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filters") final Filter filter,
        @PluginAttribute("target") final String t, @PluginAttribute("name") final String name, @PluginAttribute("follow") final String follow,
        @PluginAttribute("ignoreExceptions") final String ignore) {
    if (name == null) {
        LOGGER.error("No name provided for ConsoleAppender");
        return null;
    }
    if (layout == null) {
        layout = PatternLayout.newBuilder().build();
    }
    final boolean isFollow = Boolean.parseBoolean(follow);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final Target target = t == null ? Target.SYSTEM_OUT : Target.valueOf(t);
    FactoryData data = new FactoryData(getStream(isFollow, target), layout);
    return new JLineConsoleAppender(name, layout, filter, getManager(isFollow, target, data), getHeldManager(isFollow, target, data), ignoreExceptions);
}
项目: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   
@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    文件:ConsoleAppender.java   
/**
 * Creates a Console Appender.
 *
 * @param layout The layout to use (required).
 * @param filter The Filter or null.
 * @param targetStr The target ("SYSTEM_OUT" or "SYSTEM_ERR"). The default is "SYSTEM_OUT".
 * @param name The name of the Appender (required).
 * @param follow If true will follow changes to the underlying output stream.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise they
 *            are propagated to the caller.
 * @return The ConsoleAppender.
 * @deprecated Deprecated in 2.7; use {@link #newBuilder()}.
 */
@Deprecated
public static ConsoleAppender createAppender(Layout<? extends Serializable> layout,
        final Filter filter,
        final String targetStr,
        final String name,
        final String follow,
        final String ignore) {
    if (name == null) {
        LOGGER.error("No name provided for ConsoleAppender");
        return null;
    }
    if (layout == null) {
        layout = PatternLayout.createDefaultLayout();
    }
    final boolean isFollow = Boolean.parseBoolean(follow);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final Target target = targetStr == null ? DEFAULT_TARGET : Target.valueOf(targetStr);
    return new ConsoleAppender(name, layout, filter, getManager(target, isFollow, false, layout), ignoreExceptions, target);
}
项目:logging-log4j2    文件:RoutingAppender.java   
/**
 * Creates 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
 * @deprecated Since 2.7; use {@link #newBuilder()}
 */
@Deprecated
public static RoutingAppender createAppender(
        final String name,
        final String ignore,
        final Routes routes,
        final Configuration config,
        final RewritePolicy rewritePolicy,
        final PurgePolicy purgePolicy,
        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, purgePolicy, null);
}
项目: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    文件:ColumnConfig.java   
/**
 * Factory method for creating a column config within the plugin manager.
 *
 * @see Builder
 * @deprecated use {@link #newBuilder()}
 */
@Deprecated
public static ColumnConfig createColumnConfig(final Configuration config, final String name, final String pattern,
                                              final String literalValue, final String eventTimestamp,
                                              final String unicode, final String clob) {
    if (Strings.isEmpty(name)) {
        LOGGER.error("The column config is not valid because it does not contain a column name.");
        return null;
    }

    final boolean isEventTimestamp = Boolean.parseBoolean(eventTimestamp);
    final boolean isUnicode = Booleans.parseBoolean(unicode, true);
    final boolean isClob = Boolean.parseBoolean(clob);

    return newBuilder()
        .setConfiguration(config)
        .setName(name)
        .setPattern(pattern)
        .setLiteral(literalValue)
        .setEventTimestamp(isEventTimestamp)
        .setUnicode(isUnicode)
        .setClob(isClob)
        .build();
}
项目:logging-log4j2    文件:JdbcAppender.java   
/**
 * Factory method for creating a JDBC appender within the plugin manager.
 *
 * @see Builder
 * @deprecated use {@link #newBuilder()}
 */
@Deprecated
public static <B extends Builder<B>> JdbcAppender createAppender(final String name, final String ignore,
                                                                 final Filter filter,
                                                                 final ConnectionSource connectionSource,
                                                                 final String bufferSize, final String tableName,
                                                                 final ColumnConfig[] columnConfigs) {
    Assert.requireNonEmpty(name, "Name cannot be empty");
    Objects.requireNonNull(connectionSource, "ConnectionSource cannot be null");
    Assert.requireNonEmpty(tableName, "Table name cannot be empty");
    Assert.requireNonEmpty(columnConfigs, "ColumnConfigs cannot be empty");

    final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    return JdbcAppender.<B>newBuilder()
        .setBufferSize(bufferSizeInt)
        .setColumnConfigs(columnConfigs)
        .setConnectionSource(connectionSource)
        .setTableName(tableName)
        .withName(name)
        .withIgnoreExceptions(ignoreExceptions)
        .withFilter(filter)
        .build();
}
项目:Brynhildr    文件:FileLogAppender.java   
@PluginFactory
public static FileLogAppender createAppender(@PluginAttribute("fileName") String fileName, @PluginAttribute("filePattern") String filePattern, @PluginAttribute("append") String append, @PluginAttribute("name") String name, @PluginAttribute("immediateFlush") String immediateFlush, @PluginAttribute("bufferSize") String bufferSizeStr, @PluginElement("Policy") TriggeringPolicy policy, @PluginElement("Strategy") RolloverStrategy strategy, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") Filter filter, @PluginAttribute("ignoreExceptions") String ignore, @PluginAttribute("advertise") String advertise, @PluginAttribute("advertiseURI") String advertiseURI, @PluginConfiguration Configuration config) {
    boolean isAppend = Booleans.parseBoolean(append, true);
    boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
    boolean isAdvertise = Boolean.parseBoolean(advertise);
    int bufferSize = Integers.parseInt(bufferSizeStr, 262144);
    if (name == null) {
        LOGGER.error("No name provided for FileAppender");
        return null;
    } else if (fileName == null) {
        LOGGER.error("No filename was provided for FileAppender with name " + name);
        return null;
    } else if (filePattern == null) {
        LOGGER.error("No filename pattern provided for FileAppender with name " + name);
        return null;
    } else if (policy == null) {
        LOGGER.error("A TriggeringPolicy must be provided");
        return null;
    } else {
        if (strategy == null) {
            strategy = DefaultRolloverStrategy.createStrategy(null, null, null, String.valueOf(-1), config);
        }

        if (layout == null) {
            layout = PatternLayout.createDefaultLayout();
        }

        RollingRandomAccessFileManager manager = RollingRandomAccessFileManager.getRollingRandomAccessFileManager(fileName, filePattern, isAppend, isFlush, bufferSize, policy, strategy, advertiseURI, layout);
        return manager == null ? null : new FileLogAppender(name, layout, filter, manager, fileName, filePattern, ignoreExceptions, isFlush, bufferSize, isAdvertise ? config.getAdvertiser() : null);
    }
}
项目:log4j2-kafka-appender    文件:KafkaAppender.java   
@PluginFactory
public static KafkaAppender createAppender(@PluginAttribute("name") final String name,
                                           @PluginElement("Filter") final Filter filter,
                                           @PluginAttribute("ignoreExceptions") final String ignore,
                                           @PluginAttribute("topic") final String topic,
                                           @PluginAttribute("enable") String enable,
                                           @PluginAttribute("syncsend") String syncsend,
                                           @PluginElement("Layout") Layout<? extends Serializable> layout,
                                           @PluginElement("Properties") final Property[] properties) {
    boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    boolean enableKafka = Booleans.parseBoolean(enable, true);
    boolean sync = Booleans.parseBoolean(syncsend, false);

    KafkaProducer<String, String> producer = null;
    Map<String, Object> props = new HashMap<String, Object>();
    for (Property property : properties) {
        props.put(property.getName(), property.getValue());
    }
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");

    if(enableKafka)
       producer = new KafkaProducer<String, String>(props);

    if(layout == null) {
        layout = SerializedLayout.createLayout();
    }

    return new KafkaAppender(name, filter, layout, ignoreExceptions, producer , topic, sync);

}
项目: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);
}
项目:logging-log4j2    文件:NoSqlAppender.java   
/**
 * Factory method for creating a NoSQL appender within the plugin manager.
 *
 * @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 filter
 *            The filter, if any, to use.
 * @param bufferSize
 *            If an integer greater than 0, this causes the appender to buffer log events and flush whenever the
 *            buffer reaches this size.
 * @param provider
 *            The NoSQL provider that provides connections to the chosen NoSQL database.
 * @return a new NoSQL appender.
 * @deprecated since 2.10.1; use {@link Builder}.
 */
@SuppressWarnings("resource")
@Deprecated
public static NoSqlAppender createAppender(
// @formatter:off
        final String name,
        final String ignore, 
        final Filter filter,
        final String bufferSize,
        final NoSqlProvider<?> provider) {
// @formatter:on
    if (provider == null) {
        LOGGER.error("NoSQL provider not specified for appender [{}].", name);
        return null;
    }

    final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    final String managerName = "noSqlManager{ description=" + name + ", bufferSize=" + bufferSizeInt + ", provider="
            + provider + " }";

    final NoSqlDatabaseManager<?> manager = NoSqlDatabaseManager.getNoSqlDatabaseManager(managerName, bufferSizeInt,
            provider);
    if (manager == null) {
        return null;
    }

    return new NoSqlAppender(name, filter, null, ignoreExceptions, manager);
}
项目: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    文件:MemoryMappedFileAppender.java   
/**
 * Create a Memory Mapped File Appender.
 *
 * @param fileName The name and path of the file.
 * @param append "True" if the file should be appended to, "false" if it should be overwritten. The default is
 *            "true".
 * @param name The name of the Appender.
 * @param immediateFlush "true" if the contents should be flushed on every write, "false" otherwise. The default is
 *            "false".
 * @param regionLengthStr The buffer size, defaults to {@value MemoryMappedFileManager#DEFAULT_REGION_LENGTH}.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise they
 *            are propagated to the caller.
 * @param layout The layout to use to format the event. If no layout is provided the default PatternLayout will be
 *            used.
 * @param filter The filter, if any, to use.
 * @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 The FileAppender.
 * @deprecated Use {@link #newBuilder()}.
 */
@Deprecated
public static <B extends Builder<B>> MemoryMappedFileAppender createAppender(
        // @formatter:off
        final String fileName, //
        final String append, //
        final String name, //
        final String immediateFlush, //
        final String regionLengthStr, //
        final String ignore, //
        final Layout<? extends Serializable> layout, //
        final Filter filter, //
        final String advertise, //
        final String advertiseURI, //
        final Configuration config) {
        // @formatter:on

    final boolean isAppend = Booleans.parseBoolean(append, true);
    final boolean isImmediateFlush = Booleans.parseBoolean(immediateFlush, false);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final boolean isAdvertise = Boolean.parseBoolean(advertise);
    final int regionLength = Integers.parseInt(regionLengthStr, MemoryMappedFileManager.DEFAULT_REGION_LENGTH);

    // @formatter:off
    return MemoryMappedFileAppender.<B>newBuilder()
        .setAdvertise(isAdvertise)
        .setAdvertiseURI(advertiseURI)
        .setAppend(isAppend)
        .setConfiguration(config)
        .setFileName(fileName)
        .withFilter(filter)
        .withIgnoreExceptions(ignoreExceptions)
        .withImmediateFlush(isImmediateFlush)
        .withLayout(layout)
        .withName(name)
        .setRegionLength(regionLength)
        .build();
    // @formatter:on
}
项目:logging-log4j2    文件:RandomAccessFileAppender.java   
/**
 * Create a File Appender.
 *
 * @param fileName The name and path of the file.
 * @param append "True" if the file should be appended to, "false" if it
 *            should be overwritten. The default is "true".
 * @param name The name of the Appender.
 * @param immediateFlush "true" if the contents should be flushed on every
 *            write, "false" otherwise. The default is "true".
 * @param bufferSizeStr The buffer size, defaults to {@value RandomAccessFileManager#DEFAULT_BUFFER_SIZE}.
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param layout The layout to use to format the event. If no layout is
 *            provided the default PatternLayout will be used.
 * @param filter The filter, if any, to use.
 * @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 configuration The Configuration.
 * @return The FileAppender.
 * @deprecated Use {@link #newBuilder()}.
 */
@Deprecated
public static <B extends Builder<B>> RandomAccessFileAppender createAppender(
        final String fileName,
        final String append,
        final String name,
        final String immediateFlush,
        final String bufferSizeStr,
        final String ignore,
        final Layout<? extends Serializable> layout,
        final Filter filter,
        final String advertise,
        final String advertiseURI,
        final Configuration configuration) {

    final boolean isAppend = Booleans.parseBoolean(append, true);
    final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final boolean isAdvertise = Boolean.parseBoolean(advertise);
    final int bufferSize = Integers.parseInt(bufferSizeStr, RandomAccessFileManager.DEFAULT_BUFFER_SIZE);

    return RandomAccessFileAppender.<B>newBuilder()
        .setAdvertise(isAdvertise)
        .setAdvertiseURI(advertiseURI)
        .setAppend(isAppend)
        .withBufferSize(bufferSize)
        .setConfiguration(configuration)
        .setFileName(fileName)
        .withFilter(filter)
        .withIgnoreExceptions(ignoreExceptions)
        .withImmediateFlush(isFlush)
        .withLayout(layout)
        .withName(name)
        .build();
}
项目:logging-log4j2    文件:FileAppender.java   
/**
 * Create a File Appender.
 * @param fileName The name and path of the file.
 * @param append "True" if the file should be appended to, "false" if it should be overwritten.
 * The default is "true".
 * @param locking "True" if the file should be locked. The default is "false".
 * @param name The name of the Appender.
 * @param immediateFlush "true" if the contents should be flushed on every write, "false" otherwise. The default
 * is "true".
 * @param ignoreExceptions If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @param bufferedIo "true" if I/O should be buffered, "false" otherwise. The default is "true".
 * @param bufferSizeStr buffer size for buffered IO (default is 8192).
 * @param layout The layout to use to format the event. If no layout is provided the default PatternLayout
 * will be used.
 * @param filter The filter, if any, to use.
 * @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 The FileAppender.
 * @deprecated Use {@link #newBuilder()}
 */
@Deprecated
public static <B extends Builder<B>> FileAppender createAppender(
        // @formatter:off
        final String fileName,
        final String append,
        final String locking,
        final String name,
        final String immediateFlush,
        final String ignoreExceptions,
        final String bufferedIo,
        final String bufferSizeStr,
        final Layout<? extends Serializable> layout,
        final Filter filter,
        final String advertise,
        final String advertiseUri,
        final Configuration config) {
    return FileAppender.<B>newBuilder()
        .withAdvertise(Boolean.parseBoolean(advertise))
        .withAdvertiseUri(advertiseUri)
        .withAppend(Booleans.parseBoolean(append, true))
        .withBufferedIo(Booleans.parseBoolean(bufferedIo, true))
        .withBufferSize(Integers.parseInt(bufferSizeStr, DEFAULT_BUFFER_SIZE))
        .setConfiguration(config)
        .withFileName(fileName)
        .withFilter(filter)
        .withIgnoreExceptions(Booleans.parseBoolean(ignoreExceptions, true))
        .withImmediateFlush(Booleans.parseBoolean(immediateFlush, true))
        .withLayout(layout)
        .withLocking(Boolean.parseBoolean(locking))
        .withName(name)
        .build();
    // @formatter:on
}
项目: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));
}
项目:log4j-plugin-fluency    文件:FluencyAppender.java   
@PluginFactory
public static FluencyAppender createAppender(@PluginAttribute("name") final String name,
                                             @PluginAttribute("tag") final String tag,
                                             @PluginAttribute("application") final String application,
                                             @PluginAttribute("ignoreExceptions") final String ignore,
                                             @PluginElement("StaticField") final StaticField[] staticFields,
                                             @PluginElement("Server") final Server[] servers,
                                             @PluginElement("FluencyConfig") final FluencyConfig fluencyConfig,
                                             @PluginElement("Layout") Layout<? extends Serializable> layout,
                                             @PluginElement("Filter") final Filter filter) {
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    Map<String, Object> parameters = new HashMap<>();
    Map<String, String> fields = new HashMap<>();

    // the @Required annotation for Attributes just returns a non helpful exception, so i'll check it manually
    // we need the tag for fluency itself (it's actually a part of the fluentd protocol
    if (tag != null) {
        parameters.put("tag", tag);
    } else {
        throw new IllegalArgumentException("tag is required");
    }

    // Deprecated
    if (application != null) {
        fields.put("application", application);
    }

    for (StaticField field: staticFields) {
        if (field.getName().trim().equals("")) {
            LOG.warn("Skipping empty field");
            continue;
        }
        if (field.getValue().trim().equals("")) {
            LOG.warn("Skipping field {} due to empty value", field.getName());
            continue;
        }
        fields.put(field.getName(), field.getValue());
    }

    if (layout == null) {
        layout = PatternLayout.createDefaultLayout();
    }

    return new FluencyAppender(name, parameters, fields, servers, fluencyConfig, filter,
            layout, ignoreExceptions);
}
项目:c2w-java-client    文件:Corp2WorldAppender.java   
/**
 * Create new Corp2WorldAppender instance
 * @param name appender name
 * @param ignore if ignore exceptions
 * @param bufferSizeStr internal buffer size as number of log events
 * @param apiToken Corp2World API access token
 * @param apiKey Corp2World API access key
 * @param layout layout
 * @param filter filter
 * @return appender instance
 */
@PluginFactory
public static Corp2WorldAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginAttribute("bufferSize") final String bufferSizeStr,
        @PluginAttribute("apiToken") final String apiToken,
        @PluginAttribute("apiKey") final String apiKey,
        @PluginAttribute("topicPattern") final String topicPattern,
        @PluginElement("Layout") Layout<? extends Serializable> layout,
        @PluginElement("Filter") final Filter filter
        ) {

    /*
     * Appender name must be specified
     */
    if (name == null) {
        LOGGER.error("No name provided for FileAppender");
        return null;
    }

    /*
     * Internal queue size , use default if not specified
     */
    final int queueSize = Integers.parseInt(bufferSizeStr, DEFAULT_QUEUE_SIZE);

    /*
     * If ignore exceptions
     */
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    /*
     * Create default layout if not specified
     */
    if (layout == null) {
        layout = PatternLayout.createDefaultLayout();
    }

    /*
     * Create instance and set the properties
     */
    Corp2WorldAppender appender = new Corp2WorldAppender(name, filter, layout, ignoreExceptions);
    appender.setQueueSize(queueSize);
    appender.setApiToken(apiToken);
    appender.setApiKey(apiKey);

    if(topicPattern != null && !"".equals(topicPattern) )
        appender.setTopicLayout( PatternLayout.newBuilder().withPattern(topicPattern).withAlwaysWriteExceptions(false).build() );

    return appender;
}
项目:logging-log4j2    文件:RollingFileAppender.java   
/**
 * Creates 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 bufferSizeStr buffer size for buffered IO (default is 8192).
 * @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.
 * @deprecated Use {@link #newBuilder()}.
 */
@Deprecated
public static <B extends Builder<B>> RollingFileAppender createAppender(
        // @formatter:off
        final String fileName,
        final String filePattern,
        final String append,
        final String name,
        final String bufferedIO,
        final String bufferSizeStr,
        final String immediateFlush,
        final TriggeringPolicy policy,
        final RolloverStrategy strategy,
        final Layout<? extends Serializable> layout,
        final Filter filter,
        final String ignore,
        final String advertise,
        final String advertiseUri,
        final Configuration config) {
        // @formatter:on
    final int bufferSize = Integers.parseInt(bufferSizeStr, DEFAULT_BUFFER_SIZE);
    // @formatter:off
    return RollingFileAppender.<B>newBuilder()
            .withAdvertise(Boolean.parseBoolean(advertise))
            .withAdvertiseUri(advertiseUri)
            .withAppend(Booleans.parseBoolean(append, true))
            .withBufferedIo(Booleans.parseBoolean(bufferedIO, true))
            .withBufferSize(bufferSize)
            .setConfiguration(config)
            .withFileName(fileName)
            .withFilePattern(filePattern)
            .withFilter(filter)
            .withIgnoreExceptions(Booleans.parseBoolean(ignore, true))
            .withImmediateFlush(Booleans.parseBoolean(immediateFlush, true))
            .withLayout(layout)
            .withCreateOnDemand(false)
            .withLocking(false)
            .withName(name)
            .withPolicy(policy)
            .withStrategy(strategy)
            .build();
    // @formatter:on
}
项目:logging-log4j2    文件:RollingRandomAccessFileAppender.java   
/**
 * Create a RollingRandomAccessFileAppender.
 *
 * @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 immediateFlush When true, events are immediately flushed. Defaults
 *            to "true".
 * @param bufferSizeStr The buffer size, defaults to {@value RollingRandomAccessFileManager#DEFAULT_BUFFER_SIZE}.
 * @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 ignoreExceptions 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 configuration The Configuration.
 * @return A RollingRandomAccessFileAppender.
 * @deprecated Use {@link #newBuilder()}.
 */
@Deprecated
public static <B extends Builder<B>> RollingRandomAccessFileAppender createAppender(
        final String fileName,
        final String filePattern,
        final String append,
        final String name,
        final String immediateFlush,
        final String bufferSizeStr,
        final TriggeringPolicy policy,
        final RolloverStrategy strategy,
        final Layout<? extends Serializable> layout,
        final Filter filter,
        final String ignoreExceptions,
        final String advertise,
        final String advertiseURI,
        final Configuration configuration) {

    final boolean isAppend = Booleans.parseBoolean(append, true);
    final boolean isIgnoreExceptions = Booleans.parseBoolean(ignoreExceptions, true);
    final boolean isImmediateFlush = Booleans.parseBoolean(immediateFlush, true);
    final boolean isAdvertise = Boolean.parseBoolean(advertise);
    final int bufferSize = Integers.parseInt(bufferSizeStr, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE);

    return RollingRandomAccessFileAppender.<B>newBuilder()
       .withAdvertise(isAdvertise)
       .withAdvertiseURI(advertiseURI)
       .withAppend(isAppend)
       .withBufferSize(bufferSize)
       .setConfiguration(configuration)
       .withFileName(fileName)
       .withFilePattern(filePattern)
       .withFilter(filter)
       .withIgnoreExceptions(isIgnoreExceptions)
       .withImmediateFlush(isImmediateFlush)
       .withLayout(layout)
       .withName(name)
       .withPolicy(policy)
       .withStrategy(strategy)
       .build();
}
项目:logging-log4j2    文件:SocketAppender.java   
/**
 * Creates a socket appender.
 *
 * @param host
 *            The name of the host to connect to.
 * @param portNum
 *            The port to connect to on the target host.
 * @param protocolIn
 *            The Protocol to use.
 * @param sslConfig
 *            The SSL configuration file for TCP/SSL, ignored for UPD.
 * @param connectTimeoutMillis
 *            the connect timeout in milliseconds.
 * @param delayMillis
 *            The interval in which failed writes should be retried.
 * @param immediateFail
 *            True if the write should fail if no socket is immediately available.
 * @param name
 *            The name of the Appender.
 * @param immediateFlush
 *            "true" if data should be flushed on each write.
 * @param ignore
 *            If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise they
 *            are propagated to the caller.
 * @param layout
 *            The layout to use. Required, there is no default.
 * @param filter
 *            The Filter or null.
 * @param advertise
 *            "true" if the appender configuration should be advertised, "false" otherwise.
 * @param config
 *            The Configuration
 * @return A SocketAppender.
 * @deprecated Deprecated in 2.5; use {@link #newBuilder()}
 */
@Deprecated
public static SocketAppender createAppender(
        // @formatter:off
        final String host,
        final String portNum,
        final String protocolIn,
        final SslConfiguration sslConfig,
        final int connectTimeoutMillis,
        // deprecated
        final String delayMillis,
        final String immediateFail,
        final String name,
        final String immediateFlush,
        final String ignore,
        final Layout<? extends Serializable> layout,
        final Filter filter,
        final String advertise,
        final Configuration config) {
        // @formatter:on
    final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
    final boolean isAdvertise = Boolean.parseBoolean(advertise);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final boolean fail = Booleans.parseBoolean(immediateFail, true);
    final int reconnectDelayMillis = AbstractAppender.parseInt(delayMillis, 0);
    final int port = AbstractAppender.parseInt(portNum, 0);
    final Protocol p = protocolIn == null ? Protocol.UDP : Protocol.valueOf(protocolIn);
    return createAppender(host, port, p, sslConfig, connectTimeoutMillis, reconnectDelayMillis, fail, name, isFlush,
            ignoreExceptions, layout, filter, isAdvertise, config);
}