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;
}
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;
}
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()));
}
}
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);
}
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();
}
Aggregations