use of org.apache.log4j.spi.LoggerFactory in project jmxtrans by jmxtrans.
the class NagiosWriter method initLogger.
/**
* Initializes the logger. This is called when we need to create a new
* logger for the given file name.
*
* @param fileStr
* @return a new Logger instance for the given fileStr
* @throws IOException
*/
protected Logger initLogger(String fileStr) throws IOException {
PatternLayout pl = new PatternLayout(LOG_PATTERN);
final FileAppender appender = new FileAppender(pl, fileStr, true);
appender.setBufferedIO(false);
appender.setBufferSize(LOG_IO_BUFFER_SIZE_BYTES);
LoggerFactory loggerFactory = new LoggerFactory() {
@Override
public Logger makeNewLoggerInstance(String name) {
Logger logger = Logger.getLogger(name);
logger.addAppender(appender);
logger.setLevel(Level.INFO);
logger.setAdditivity(false);
return logger;
}
};
return loggerFactory.makeNewLoggerInstance("NagiosWriter" + this.hashCode());
}
use of org.apache.log4j.spi.LoggerFactory in project jmxtrans by jmxtrans.
the class KeyOutWriter method initLogger.
/**
* Initializes the logger. This is called when we need to create a new
* logger for the given file name.
*
* @param fileStr
* @return a new Logger instance for the given fileStr
* @throws IOException
*/
protected Logger initLogger(String fileStr) throws IOException {
Appender appender = buildLog4jAppender(fileStr, getMaxLogFileSize(), getMaxLogBackupFiles());
LoggerFactory loggerFactory = buildLog4jLoggerFactory(appender);
String loggerKey = buildLoggerName();
// Create the logger and add to the map of loggers using our factory
LogManager.getLogger(loggerKey, loggerFactory);
return log4jLoggerFactory.getLogger(loggerKey);
}
Aggregations