Search in sources :

Example 11 with RollingFileAppender

use of org.apache.log4j.RollingFileAppender in project jmxtrans by jmxtrans.

the class KeyOutWriter method buildLog4jAppender.

protected Appender buildLog4jAppender(String fileStr, String maxLogFileSize, Integer maxLogBackupFiles) throws IOException {
    PatternLayout pl = new PatternLayout(LOG_PATTERN);
    final RollingFileAppender appender = new RollingFileAppender(pl, fileStr, true);
    appender.setImmediateFlush(true);
    appender.setBufferedIO(false);
    appender.setBufferSize(LOG_IO_BUFFER_SIZE_BYTES);
    appender.setMaxFileSize(maxLogFileSize);
    appender.setMaxBackupIndex(maxLogBackupFiles);
    return appender;
}
Also used : RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout)

Example 12 with RollingFileAppender

use of org.apache.log4j.RollingFileAppender in project apex-core by apache.

the class StdOutErrLog method tieSystemOutAndErrToLog.

@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void tieSystemOutAndErrToLog() {
    org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
    Appender appender = rootLogger.getAppender(DT_LOG_APPENDER);
    if (appender instanceof RollingFileAppender) {
        RollingFileAppender rfa = (RollingFileAppender) appender;
        if (rfa.getFile() == null || rfa.getFile().isEmpty()) {
            rfa.setFile(System.getProperty(DT_LOGDIR));
            rfa.activateOptions();
        }
    } else if (appender != null) {
        logger.warn("found appender {} instead of RollingFileAppender", appender);
    }
    LoggerUtil.addAppenders();
    System.setOut(createLoggingProxy(System.out));
    System.setErr(createLoggingProxy(System.err));
}
Also used : Appender(org.apache.log4j.Appender) RollingFileAppender(org.apache.log4j.RollingFileAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender)

Example 13 with RollingFileAppender

use of org.apache.log4j.RollingFileAppender in project apex-core by apache.

the class LogFileInformationTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException {
    String logFileDir = new File("target" + File.separator + "logDir").getAbsolutePath();
    logFileName = logFileDir + File.separator + "appTest.log";
    RollingFileAppender rfa = new RollingFileAppender(new PatternLayout("%d{ISO8601} [%t] %-5p %c{2} %M - %m%n"), logFileName);
    rfa.setName(APPENDER_NAME);
    Logger.getRootLogger().addAppender(rfa);
}
Also used : RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 14 with RollingFileAppender

use of org.apache.log4j.RollingFileAppender in project apex-core by apache.

the class LogFileInformationTest method testNoFileAppender.

@Test
public void testNoFileAppender() {
    RollingFileAppender rfa = (RollingFileAppender) Logger.getRootLogger().getAppender(APPENDER_NAME);
    Logger.getRootLogger().removeAppender(APPENDER_NAME);
    LoggerUtil.initializeLogger();
    Assert.assertNull(LoggerUtil.getLogFileInformation());
    Logger.getRootLogger().addAppender(rfa);
}
Also used : RollingFileAppender(org.apache.log4j.RollingFileAppender) Test(org.junit.Test)

Example 15 with RollingFileAppender

use of org.apache.log4j.RollingFileAppender in project dhis2-core by dhis2.

the class Log4JLogConfigInitializer method configureLoggers.

/**
     * Configures rolling file loggers.
     * 
     * @param filename the filename to output logging to.
     * @param loggers the logger names.
     */
private void configureLoggers(String filename, List<String> loggers) {
    String file = getLogFile(filename);
    RollingFileAppender appender = getRollingFileAppender(file);
    for (String loggerName : loggers) {
        Logger logger = Logger.getRootLogger().getLoggerRepository().getLogger(loggerName);
        logger.addAppender(appender);
        log.info("Added logger: " + loggerName + " using file: " + file);
    }
}
Also used : RollingFileAppender(org.apache.log4j.RollingFileAppender) Logger(org.apache.log4j.Logger)

Aggregations

RollingFileAppender (org.apache.log4j.RollingFileAppender)16 PatternLayout (org.apache.log4j.PatternLayout)8 Logger (org.apache.log4j.Logger)6 File (java.io.File)4 IOException (java.io.IOException)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)3 ConsoleAppender (org.apache.log4j.ConsoleAppender)3 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 Appender (org.apache.log4j.Appender)2 LevelRangeFilter (org.apache.log4j.varia.LevelRangeFilter)2 Test (org.junit.Test)2 RandomAccessFile (java.io.RandomAccessFile)1 NullLogger (org.apache.ignite.logger.NullLogger)1 FileAppender (org.apache.log4j.FileAppender)1 BeforeClass (org.junit.BeforeClass)1 Logger (org.slf4j.Logger)1