Search in sources :

Example 6 with RollingFileAppender

use of org.apache.logging.log4j.core.appender.RollingFileAppender in project logging-log4j2 by apache.

the class Log4j1ConfigurationFactoryTest method testRollingFileAppender.

private void testRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
    final Configuration configuration = getConfiguration(configResource);
    final Appender appender = configuration.getAppender(name);
    assertNotNull(appender);
    assertEquals(name, appender.getName());
    assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
    final RollingFileAppender rfa = (RollingFileAppender) appender;
    assertEquals("target/hadoop.log", rfa.getFileName());
    assertEquals(filePattern, rfa.getFilePattern());
    final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
    assertNotNull(triggeringPolicy);
    assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
    final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
    final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
    assertEquals(1, triggeringPolicies.length);
    final TriggeringPolicy tp = triggeringPolicies[0];
    assertTrue(tp.getClass().getName(), tp instanceof SizeBasedTriggeringPolicy);
    final SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) tp;
    assertEquals(256 * 1024 * 1024, sbtp.getMaxFileSize());
    final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
    assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
    final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
    assertEquals(20, drs.getMaxIndex());
    configuration.start();
    configuration.stop();
}
Also used : Appender(org.apache.logging.log4j.core.Appender) NullAppender(org.apache.logging.log4j.core.appender.NullAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy) RolloverStrategy(org.apache.logging.log4j.core.appender.rolling.RolloverStrategy) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) 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) DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy)

Example 7 with RollingFileAppender

use of org.apache.logging.log4j.core.appender.RollingFileAppender in project logging-log4j2 by apache.

the class Log4j1ConfigurationFactoryTest method testDailyRollingFileAppender.

private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
    final Configuration configuration = getConfiguration(configResource);
    final Appender appender = configuration.getAppender(name);
    assertNotNull(appender);
    assertEquals(name, appender.getName());
    assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
    final RollingFileAppender rfa = (RollingFileAppender) appender;
    assertEquals("target/hadoop.log", rfa.getFileName());
    assertEquals(filePattern, rfa.getFilePattern());
    final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
    assertNotNull(triggeringPolicy);
    assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
    final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
    final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
    assertEquals(1, triggeringPolicies.length);
    final TriggeringPolicy tp = triggeringPolicies[0];
    assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
    final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
    assertEquals(1, tbtp.getInterval());
    final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
    assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
    final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
    assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
    configuration.start();
    configuration.stop();
}
Also used : Appender(org.apache.logging.log4j.core.Appender) NullAppender(org.apache.logging.log4j.core.appender.NullAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) Configuration(org.apache.logging.log4j.core.config.Configuration) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) 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) DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy)

Example 8 with RollingFileAppender

use of org.apache.logging.log4j.core.appender.RollingFileAppender in project ignite by apache.

the class Log4J2Logger method fileName.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public String fileName() {
    for (Logger log = impl; log != null; log = log.getParent()) {
        for (Appender a : log.getAppenders().values()) {
            if (a instanceof FileAppender)
                return ((FileAppender) a).getFileName();
            if (a instanceof RollingFileAppender)
                return ((RollingFileAppender) a).getFileName();
            if (a instanceof RoutingAppender) {
                try {
                    RoutingAppender routing = (RoutingAppender) a;
                    Field appsFiled = routing.getClass().getDeclaredField("appenders");
                    appsFiled.setAccessible(true);
                    Map<String, AppenderControl> appenders = (Map<String, AppenderControl>) appsFiled.get(routing);
                    for (AppenderControl control : appenders.values()) {
                        Appender innerApp = control.getAppender();
                        if (innerApp instanceof FileAppender)
                            return normalize(((FileAppender) innerApp).getFileName());
                        if (innerApp instanceof RollingFileAppender)
                            return normalize(((RollingFileAppender) innerApp).getFileName());
                    }
                } catch (IllegalAccessException | NoSuchFieldException e) {
                    error("Failed to get file name (was the implementation of log4j2 changed?).", e);
                }
            }
        }
    }
    return null;
}
Also used : Appender(org.apache.logging.log4j.core.Appender) RoutingAppender(org.apache.logging.log4j.core.appender.routing.RoutingAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) AppenderControl(org.apache.logging.log4j.core.config.AppenderControl) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.logging.log4j.core.Logger) Field(java.lang.reflect.Field) RoutingAppender(org.apache.logging.log4j.core.appender.routing.RoutingAppender) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with RollingFileAppender

use of org.apache.logging.log4j.core.appender.RollingFileAppender in project cas by apereo.

the class LoggingOutputTailingService method registerLogFileTailersForExecution.

private void registerLogFileTailersForExecution(final LoggerContext loggerContext) {
    final Collection<String> outputFileNames = new HashSet<>();
    final Collection<Appender> loggerAppenders = loggerContext.getConfiguration().getAppenders().values();
    loggerAppenders.forEach(appender -> {
        if (appender instanceof FileAppender) {
            outputFileNames.add(FileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof RandomAccessFileAppender) {
            outputFileNames.add(RandomAccessFileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            outputFileNames.add(RollingFileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof MemoryMappedFileAppender) {
            outputFileNames.add(MemoryMappedFileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof RollingRandomAccessFileAppender) {
            outputFileNames.add(RollingRandomAccessFileAppender.class.cast(appender).getFileName());
        }
    });
    outputFileNames.forEach(f -> {
        final Tailer t = new Tailer(new File(f), this, 100L, false, true);
        this.tailers.add(t);
        this.taskExecutor.execute(t);
    });
}
Also used : RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Appender(org.apache.logging.log4j.core.Appender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) Tailer(org.apache.commons.io.input.Tailer) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) File(java.io.File) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) HashSet(java.util.HashSet)

Example 10 with RollingFileAppender

use of org.apache.logging.log4j.core.appender.RollingFileAppender in project hive by apache.

the class HadoopJobExecHelper method localJobDebugger.

public void localJobDebugger(int exitVal, String taskId) {
    StringBuilder sb = new StringBuilder();
    sb.append("\n");
    sb.append("Task failed!\n");
    sb.append("Task ID:\n  " + taskId + "\n\n");
    sb.append("Logs:\n");
    console.printError(sb.toString());
    for (Appender appender : ((Logger) LogManager.getRootLogger()).getAppenders().values()) {
        if (appender instanceof FileAppender) {
            console.printError(((FileAppender) appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            console.printError(((RollingFileAppender) appender).getFileName());
        }
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender)

Aggregations

RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)18 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)9 Appender (org.apache.logging.log4j.core.Appender)8 Test (org.junit.Test)8 File (java.io.File)7 Configuration (org.apache.logging.log4j.core.config.Configuration)7 HashSet (java.util.HashSet)3 LoggerContext (org.apache.logging.log4j.core.LoggerContext)3 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)3 CompositeTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy)3 SizeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy)3 TimeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy)3 TriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 Tailer (org.apache.commons.io.input.Tailer)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 DriverContext (org.apache.hadoop.hive.ql.DriverContext)2