Search in sources :

Example 51 with PatternLayout

use of org.apache.log4j.PatternLayout in project leopard by tanhaichao.

the class LogDaoLog4jImpl method getAppender.

protected Appender getAppender(String filename, org.apache.log4j.Level log4jLevel, boolean bufferedIO) {
    String key = filename + ":" + log4jLevel.toInt() + ":" + bufferedIO;
    DailyAutoRollingFileAppender appender = appenderMap.get(key);
    if (appender != null) {
        return appender;
    }
    String conversionPattern = "%d{yyyy-MM-dd HH:mm:ss} - [%c] - %m%n";
    org.apache.log4j.PatternLayout layout = new PatternLayout();
    layout.setConversionPattern(conversionPattern);
    appender = new DailyAutoRollingFileAppender();
    // DailyRollingFileAppender newAppender = new DailyRollingFileAppender();
    appender.setThreshold(log4jLevel);
    appender.setLayout(layout);
    appender.setDatePattern(".yyyyMMdd");
    appender.setFile(filename);
    // 8192
    appender.setBufferSize(10);
    appender.setBufferedIO(bufferedIO);
    appender.activateOptions();
    appenderMap.put(key, appender);
    return appender;
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) PatternLayout(org.apache.log4j.PatternLayout)

Example 52 with PatternLayout

use of org.apache.log4j.PatternLayout 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 53 with PatternLayout

use of org.apache.log4j.PatternLayout in project gerrit by GerritCodeReview.

the class ErrorLogFile method initLogSystem.

private static void initLogSystem(Path logdir, Config config) {
    final Logger root = LogManager.getRootLogger();
    root.removeAllAppenders();
    boolean json = config.getBoolean("log", "jsonLogging", false);
    boolean text = config.getBoolean("log", "textLogging", true) || !json;
    if (text) {
        root.addAppender(SystemLog.createAppender(logdir, LOG_NAME, new PatternLayout("[%d] [%t] %-5p %c %x: %m%n")));
    }
    if (json) {
        root.addAppender(SystemLog.createAppender(logdir, LOG_NAME + JSON_SUFFIX, new JSONEventLayoutV1()));
    }
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) JSONEventLayoutV1(net.logstash.log4j.JSONEventLayoutV1) Logger(org.apache.log4j.Logger)

Example 54 with PatternLayout

use of org.apache.log4j.PatternLayout in project gerrit by GerritCodeReview.

the class GarbageCollectionLogFile method initLogSystem.

private static void initLogSystem(Path logdir) {
    Logger gcLogger = LogManager.getLogger(GarbageCollection.LOG_NAME);
    gcLogger.removeAllAppenders();
    gcLogger.addAppender(SystemLog.createAppender(logdir, GarbageCollection.LOG_NAME, new PatternLayout("[%d] %-5p %x: %m%n")));
    gcLogger.setAdditivity(false);
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) Logger(org.apache.log4j.Logger)

Example 55 with PatternLayout

use of org.apache.log4j.PatternLayout in project hadoop by apache.

the class TestContainerLogAppender method testAppendInClose.

@Test
public void testAppendInClose() throws Exception {
    final ContainerLogAppender claAppender = new ContainerLogAppender();
    claAppender.setName("testCLA");
    claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
    claAppender.setContainerLogDir("target/testAppendInClose/logDir");
    claAppender.setContainerLogFile("syslog");
    claAppender.setTotalLogFileSize(1000);
    claAppender.activateOptions();
    final Logger claLog = Logger.getLogger("testAppendInClose-catergory");
    claLog.setAdditivity(false);
    claLog.addAppender(claAppender);
    claLog.info(new Object() {

        public String toString() {
            claLog.info("message1");
            return "return message1";
        }
    });
    claAppender.close();
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) Logger(org.apache.log4j.Logger) Test(org.junit.Test)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)101 ConsoleAppender (org.apache.log4j.ConsoleAppender)51 Logger (org.apache.log4j.Logger)27 IOException (java.io.IOException)21 Appender (org.apache.log4j.Appender)18 FileAppender (org.apache.log4j.FileAppender)17 Layout (org.apache.log4j.Layout)15 File (java.io.File)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 FileInputStream (java.io.FileInputStream)6 Properties (java.util.Properties)6 CommandLine (org.apache.commons.cli.CommandLine)6 Option (org.apache.commons.cli.Option)6 Options (org.apache.commons.cli.Options)6 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)6 WriterAppender (org.apache.log4j.WriterAppender)6