Search in sources :

Example 6 with AppenderComponentBuilder

use of org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder in project logging-log4j2 by apache.

the class Log4j1ConfigurationParser method buildDailyRollingFileAppender.

private void buildDailyRollingFileAppender(final String appenderName) {
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, RollingFileAppender.PLUGIN_NAME);
    buildFileAppender(appenderName, appenderBuilder);
    final String fileName = getLog4jAppenderValue(appenderName, "File");
    final String datePattern = getLog4jAppenderValue(appenderName, "DatePattern", fileName + "'.'yyyy-MM-dd");
    appenderBuilder.addAttribute("filePattern", fileName + "%d{" + datePattern + "}");
    final ComponentBuilder<?> triggeringPolicy = builder.newComponent("Policies").addComponent(builder.newComponent("TimeBasedTriggeringPolicy").addAttribute("modulate", true));
    appenderBuilder.addComponent(triggeringPolicy);
    appenderBuilder.addComponent(builder.newComponent("DefaultRolloverStrategy").addAttribute("max", Integer.MAX_VALUE));
    builder.add(appenderBuilder);
}
Also used : AppenderComponentBuilder(org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder)

Example 7 with AppenderComponentBuilder

use of org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder in project logging-log4j2 by apache.

the class Log4j1ConfigurationParser method buildRollingFileAppender.

private void buildRollingFileAppender(final String appenderName) {
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, RollingFileAppender.PLUGIN_NAME);
    buildFileAppender(appenderName, appenderBuilder);
    final String fileName = getLog4jAppenderValue(appenderName, "File");
    appenderBuilder.addAttribute("filePattern", fileName + ".%i");
    final String maxFileSizeString = getLog4jAppenderValue(appenderName, "MaxFileSize", "10485760");
    final String maxBackupIndexString = getLog4jAppenderValue(appenderName, "MaxBackupIndex", "1");
    final ComponentBuilder<?> triggeringPolicy = builder.newComponent("Policies").addComponent(builder.newComponent("SizeBasedTriggeringPolicy").addAttribute("size", maxFileSizeString));
    appenderBuilder.addComponent(triggeringPolicy);
    appenderBuilder.addComponent(builder.newComponent("DefaultRolloverStrategy").addAttribute("max", maxBackupIndexString));
    builder.add(appenderBuilder);
}
Also used : AppenderComponentBuilder(org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder)

Example 8 with AppenderComponentBuilder

use of org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder in project logging-log4j2 by apache.

the class PropertiesConfigurationBuilder method createAppender.

private AppenderComponentBuilder createAppender(final String key, final Properties properties) {
    final String name = (String) properties.remove(CONFIG_NAME);
    if (Strings.isEmpty(name)) {
        throw new ConfigurationException("No name attribute provided for Appender " + key);
    }
    final String type = (String) properties.remove(CONFIG_TYPE);
    if (Strings.isEmpty(type)) {
        throw new ConfigurationException("No type attribute provided for Appender " + key);
    }
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(name, type);
    addFiltersToComponent(appenderBuilder, properties);
    final Properties layoutProps = PropertiesUtil.extractSubset(properties, "layout");
    if (layoutProps.size() > 0) {
        appenderBuilder.add(createLayout(name, layoutProps));
    }
    return processRemainingProperties(appenderBuilder, properties);
}
Also used : AppenderComponentBuilder(org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder) ConfigurationException(org.apache.logging.log4j.core.config.ConfigurationException) Properties(java.util.Properties)

Example 9 with AppenderComponentBuilder

use of org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder in project logging-log4j2 by apache.

the class Log4j1ConfigurationParser method buildConsoleAppender.

private void buildConsoleAppender(final String appenderName) {
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, ConsoleAppender.PLUGIN_NAME);
    final String targetValue = getLog4jAppenderValue(appenderName, "Target", "System.out");
    if (targetValue != null) {
        final ConsoleAppender.Target target;
        switch(targetValue) {
            case "System.out":
                target = ConsoleAppender.Target.SYSTEM_OUT;
                break;
            case "System.err":
                target = ConsoleAppender.Target.SYSTEM_ERR;
                break;
            default:
                reportWarning("Unknown value for console Target: " + targetValue);
                target = null;
        }
        if (target != null) {
            appenderBuilder.addAttribute("target", target);
        }
    }
    buildAttribute(appenderName, appenderBuilder, "Follow", "follow");
    if (FALSE.equalsIgnoreCase(getLog4jAppenderValue(appenderName, "ImmediateFlush"))) {
        reportWarning("ImmediateFlush=false is not supported on Console appender");
    }
    buildAppenderLayout(appenderName, appenderBuilder);
    builder.add(appenderBuilder);
}
Also used : ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) AppenderComponentBuilder(org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder)

Example 10 with AppenderComponentBuilder

use of org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder in project logging-log4j2 by apache.

the class Log4j1ConfigurationParser method buildNullAppender.

private void buildNullAppender(final String appenderName) {
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, NullAppender.PLUGIN_NAME);
    builder.add(appenderBuilder);
}
Also used : AppenderComponentBuilder(org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder)

Aggregations

AppenderComponentBuilder (org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder)12 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)4 Test (org.junit.Test)3 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)2 Properties (java.util.Properties)1 Appender (org.apache.logging.log4j.core.Appender)1 ErrorHandler (org.apache.logging.log4j.core.ErrorHandler)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1 ConfigurationException (org.apache.logging.log4j.core.config.ConfigurationException)1 ComponentBuilder (org.apache.logging.log4j.core.config.builder.api.ComponentBuilder)1 LayoutComponentBuilder (org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder)1 RootLoggerComponentBuilder (org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder)1 BeforeClass (org.junit.BeforeClass)1