org.apache.logging.log4j.core.util.Booleans Java Examples

The following examples show how to use org.apache.logging.log4j.core.util.Booleans. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggerConfig.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@PluginFactory
public static LoggerConfig createLogger(
        // @formatter:off
        @PluginAttribute final String additivity,
        @PluginAttribute final Level level,
        @PluginAttribute final String includeLocation,
        @PluginElement final AppenderRef[] refs,
        @PluginElement final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement 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, config));
}
 
Example #2
Source File: AsyncLoggerConfig.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * @since 3.0
 */
@PluginFactory
public static LoggerConfig createLogger(
        @PluginAttribute final String additivity,
        @PluginAttribute final Level level,
        @PluginAttribute final String includeLocation,
        @PluginElement final AppenderRef[] refs,
        @PluginElement final Property[] properties,
        @PluginConfiguration final Configuration config,
        @PluginElement final Filter filter) {
    final List<AppenderRef> appenderRefs = Arrays.asList(refs);
    final Level actualLevel = level == null ? Level.ERROR : level;
    final boolean additive = Booleans.parseBoolean(additivity, true);
    return new AsyncLoggerConfig(LogManager.ROOT_LOGGER_NAME, appenderRefs, filter, actualLevel, additive,
            properties, config, AsyncLoggerConfig.includeLocation(includeLocation));
}
 
Example #3
Source File: RollbarAppender.java    From rollbar-java with MIT License 5 votes vote down vote up
/**
 * Create appender plugin factory method.
 *
 * @param accessToken the Rollbar access token.
 * @param codeVersion the codeVersion.
 * @param endpoint the Rollbar endpoint to be used.
 * @param environment the environment.
 * @param language the language.
 * @param enabled to enable or disable Rollbar.
 * @param configProviderClassName The class name of the config provider implementation to get
 *     the configuration.
 * @param name the name.
 * @param layout the layout.
 * @param filter the filter.
 * @param ignore the ignore exceptions flag.
 * @return the rollbar appender.
 */
@PluginFactory
public static RollbarAppender createAppender(
    @PluginAttribute("accessToken") @Required final String accessToken,
    @PluginAttribute("codeVersion") final String codeVersion,
    @PluginAttribute("endpoint") final String endpoint,
    @PluginAttribute("environment") final String environment,
    @PluginAttribute("language") final String language,
    @PluginAttribute("enabled") final boolean enabled,
    @PluginAttribute("configProviderClassName") final String configProviderClassName,
    @PluginAttribute("name") @Required final String name,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginElement("Filter") Filter filter,
    @PluginAttribute("ignoreExceptions") final String ignore
) {

  ConfigProvider configProvider = ConfigProviderHelper
      .getConfigProvider(configProviderClassName);
  Config config;

  ConfigBuilder configBuilder = withAccessToken(accessToken)
      .codeVersion(codeVersion)
      .environment(environment)
      .endpoint(endpoint)
      .server(new ServerProvider())
      .language(language)
      .enabled(enabled);

  if (configProvider != null) {
    config = configProvider.provide(configBuilder);
  } else {
    config = configBuilder.build();
  }

  Rollbar rollbar = new Rollbar(config);

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

  return new RollbarAppender(name, filter, layout, ignoreExceptions, rollbar);
}
 
Example #4
Source File: SystemdJournalAppender.java    From log4j-systemd-journal-appender with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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,
        @PluginAttribute("syslogFacility") final String syslogFacility,
        @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;
    }

    final SystemdJournalLibrary journalLibrary;
    try {
        journalLibrary = Native.loadLibrary("systemd", SystemdJournalLibrary.class);
    } catch (UnsatisfiedLinkError e) {
        throw new RuntimeException("Failed to load systemd library." +
            " Please note that JNA requires an executable temporary folder." +
            " It can be explicitly defined with -Djna.tmpdir", e);
    }

    return new SystemdJournalAppender(name, filter, layout, ignoreExceptions, journalLibrary, logSource, logStacktrace,
            logThreadName, logLoggerName, logAppenderName, logThreadContext, threadContextPrefix, syslogIdentifier, syslogFacility);
}
 
Example #5
Source File: SmtpAppender.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a SmtpAppender.
 * @deprecated Use {@link #newBuilder()} to create and configure a {@link Builder} instance.
 * @see Builder
 */
public static SmtpAppender createAppender(final Configuration config, final String name, final String to,
                                          final String cc, final String bcc, final String from,
                                          final String replyTo, final String subject, final String smtpProtocol,
                                          final String smtpHost, final String smtpPortStr,
                                          final String smtpUsername, final String smtpPassword,
                                          final String smtpDebug, final String bufferSizeStr,
                                          Layout<? extends Serializable> layout, Filter filter,
                                          final String ignore) {
    if (name == null) {
        LOGGER.error("No name provided for SmtpAppender");
        return null;
    }

    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final int smtpPort = AbstractAppender.parseInt(smtpPortStr, 0);
    final boolean isSmtpDebug = Boolean.parseBoolean(smtpDebug);
    final int bufferSize = bufferSizeStr == null ? DEFAULT_BUFFER_SIZE : Integer.parseInt(bufferSizeStr);

    if (layout == null) {
        layout = HtmlLayout.createDefaultLayout();
    }
    if (filter == null) {
        filter = ThresholdFilter.createFilter(null, null, null);
    }
    final Configuration configuration = config != null ? config : new DefaultConfiguration();

    final SmtpManager manager = SmtpManager.getSmtpManager(configuration, to, cc, bcc, from, replyTo, subject, smtpProtocol,
        smtpHost, smtpPort, smtpUsername, smtpPassword, isSmtpDebug, filter.toString(),  bufferSize, null);
    if (manager == null) {
        return null;
    }

    return new SmtpAppender(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY, manager);
}
 
Example #6
Source File: LoghubAppender.java    From aliyun-log-log4j2-appender with Apache License 2.0 4 votes vote down vote up
@PluginFactory
public static LoghubAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginElement("Filter") final Filter filter,
        @PluginElement("Layout") Layout<? extends Serializable> layout,
        @PluginConfiguration final Configuration config,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginAttribute("project") final String project,
        @PluginAttribute("logStore") final String logStore,
        @PluginAttribute("endpoint") final String endpoint,
        @PluginAttribute("accessKeyId") final String accessKeyId,
        @PluginAttribute("accessKeySecret") final String accessKeySecret,
        @PluginAttribute("stsToken") final String stsToken,

        @PluginAttribute("totalSizeInBytes") final String  totalSizeInBytes,
        @PluginAttribute("maxBlockMs") final String  maxBlockMs,
        @PluginAttribute("ioThreadCount") final String  ioThreadCount,
        @PluginAttribute("batchSizeThresholdInBytes") final String  batchSizeThresholdInBytes,
        @PluginAttribute("batchCountThreshold") final String  batchCountThreshold,
        @PluginAttribute("lingerMs") final String  lingerMs,
        @PluginAttribute("retries") final String  retries,
        @PluginAttribute("baseRetryBackoffMs") final String  baseRetryBackoffMs,
        @PluginAttribute("maxRetryBackoffMs") final String maxRetryBackoffMs,

        @PluginAttribute("topic") final String topic,
        @PluginAttribute("source") final String source,
        @PluginAttribute("timeFormat") final String timeFormat,
        @PluginAttribute("timeZone") final String timeZone,
        @PluginAttribute("mdcFields") final String mdcFields) {

    Boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    int maxBlockMsInt = parseStrToInt(maxBlockMs, 60);

    int baseRetryBackoffMsInt = parseStrToInt(baseRetryBackoffMs, 100);

    int maxRetryBackoffMsInt = parseStrToInt(maxRetryBackoffMs, 100);

    int lingerMsInt = parseStrToInt(lingerMs, 3000);

    int batchCountThresholdInt = parseStrToInt(batchCountThreshold, 4096);

    int batchSizeThresholdInBytesInt = parseStrToInt(batchSizeThresholdInBytes, 5 * 1024 * 1024);

    int totalSizeInBytesInt = parseStrToInt(totalSizeInBytes, 104857600);

    int retriesInt = parseStrToInt(retries, 3);

    int ioThreadCountInt = parseStrToInt(ioThreadCount, 8);

    String pattern = isStrEmpty(timeFormat) ? DEFAULT_TIME_FORMAT : timeFormat;
    String timeZoneInfo = isStrEmpty(timeZone) ? DEFAULT_TIME_ZONE : timeZone;
    DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.forID(timeZoneInfo));

    return new LoghubAppender(name, filter, layout, ignoreExceptions, project, logStore, endpoint,
            accessKeyId, accessKeySecret, stsToken,totalSizeInBytesInt,maxBlockMsInt,ioThreadCountInt,
            batchSizeThresholdInBytesInt,batchCountThresholdInt,lingerMsInt,retriesInt,
            baseRetryBackoffMsInt, maxRetryBackoffMsInt,topic, source, formatter,mdcFields);
}