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