Search in sources :

Example 1 with LayoutAdapter

use of org.apache.log4j.bridge.LayoutAdapter in project logging-log4j2 by apache.

the class DailyRollingFileAppenderBuilder method createAppender.

private <T extends Log4j1Configuration> Appender createAppender(final String name, final Layout layout, final Filter filter, final String fileName, final boolean append, boolean immediateFlush, final String level, final boolean bufferedIo, final int bufferSize, final T configuration) {
    org.apache.logging.log4j.core.Layout<?> fileLayout = null;
    if (bufferedIo) {
        immediateFlush = true;
    }
    if (layout instanceof LayoutWrapper) {
        fileLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        fileLayout = new LayoutAdapter(layout);
    }
    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    if (fileName == null) {
        LOGGER.warn("Unable to create File Appender, no file name provided");
        return null;
    }
    String filePattern = fileName + "%d{.yyyy-MM-dd}";
    TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
    TriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(timePolicy);
    RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder().setConfig(configuration).setMax(Integer.toString(Integer.MAX_VALUE)).build();
    return new AppenderWrapper(RollingFileAppender.newBuilder().setName(name).setConfiguration(configuration).setLayout(fileLayout).setFilter(fileFilter).setFileName(fileName).setBufferSize(bufferSize).setImmediateFlush(immediateFlush).setFilePattern(filePattern).setPolicy(policy).setStrategy(strategy).build());
}
Also used : DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy) RolloverStrategy(org.apache.logging.log4j.core.appender.rolling.RolloverStrategy) AppenderWrapper(org.apache.log4j.bridge.AppenderWrapper) TriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) LayoutWrapper(org.apache.log4j.bridge.LayoutWrapper) LayoutAdapter(org.apache.log4j.bridge.LayoutAdapter)

Example 2 with LayoutAdapter

use of org.apache.log4j.bridge.LayoutAdapter in project logging-log4j2 by apache.

the class RollingFileAppenderBuilder method createAppender.

private Appender createAppender(final String name, final Log4j1Configuration config, final Layout layout, final Filter filter, final boolean bufferedIo, boolean immediateFlush, final String fileName, final String level, final String maxSize, final String maxBackups) {
    org.apache.logging.log4j.core.Layout<?> fileLayout = null;
    if (bufferedIo) {
        immediateFlush = true;
    }
    if (layout instanceof LayoutWrapper) {
        fileLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        fileLayout = new LayoutAdapter(layout);
    }
    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    if (fileName == null) {
        LOGGER.warn("Unable to create File Appender, no file name provided");
        return null;
    }
    String filePattern = fileName + ".%i";
    TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
    SizeBasedTriggeringPolicy sizePolicy = SizeBasedTriggeringPolicy.createPolicy(maxSize);
    CompositeTriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(sizePolicy);
    RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder().setConfig(config).setMax(maxBackups).build();
    return new AppenderWrapper(RollingFileAppender.newBuilder().setName(name).setConfiguration(config).setLayout(fileLayout).setFilter(fileFilter).setBufferedIo(bufferedIo).setImmediateFlush(immediateFlush).setFileName(fileName).setFilePattern(filePattern).setPolicy(policy).setStrategy(strategy).build());
}
Also used : DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy) RolloverStrategy(org.apache.logging.log4j.core.appender.rolling.RolloverStrategy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) LayoutWrapper(org.apache.log4j.bridge.LayoutWrapper) AppenderWrapper(org.apache.log4j.bridge.AppenderWrapper) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) LayoutAdapter(org.apache.log4j.bridge.LayoutAdapter)

Example 3 with LayoutAdapter

use of org.apache.log4j.bridge.LayoutAdapter in project logging-log4j2 by apache.

the class SyslogAppenderBuilder method createAppender.

private Appender createAppender(final String name, final Log4j1Configuration configuration, Layout layout, String facility, final Filter filter, final String syslogHost, final String level, final Protocol protocol) {
    AtomicReference<String> host = new AtomicReference<>();
    AtomicInteger port = new AtomicInteger();
    resolveSyslogHost(syslogHost, host, port);
    org.apache.logging.log4j.core.Layout<? extends Serializable> appenderLayout;
    if (layout instanceof LayoutWrapper) {
        appenderLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        appenderLayout = new LayoutAdapter(layout);
    } else {
        appenderLayout = SyslogLayout.newBuilder().setFacility(Facility.toFacility(facility)).setConfiguration(configuration).build();
    }
    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    return new AppenderWrapper(SocketAppender.newBuilder().setName(name).setConfiguration(configuration).setLayout(appenderLayout).setFilter(fileFilter).setPort(port.get()).setProtocol(protocol).setHost(host.get()).build());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AppenderWrapper(org.apache.log4j.bridge.AppenderWrapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) LayoutWrapper(org.apache.log4j.bridge.LayoutWrapper) LayoutAdapter(org.apache.log4j.bridge.LayoutAdapter)

Aggregations

AppenderWrapper (org.apache.log4j.bridge.AppenderWrapper)3 LayoutAdapter (org.apache.log4j.bridge.LayoutAdapter)3 LayoutWrapper (org.apache.log4j.bridge.LayoutWrapper)3 CompositeTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy)2 DefaultRolloverStrategy (org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy)2 RolloverStrategy (org.apache.logging.log4j.core.appender.rolling.RolloverStrategy)2 TimeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy)2 TriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 SizeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy)1