Search in sources :

Example 1 with LoggerFactory

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());
}
Also used : FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) LoggerFactory(org.apache.log4j.spi.LoggerFactory) Logger(org.apache.log4j.Logger)

Example 2 with LoggerFactory

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);
}
Also used : Appender(org.apache.log4j.Appender) RollingFileAppender(org.apache.log4j.RollingFileAppender) LoggerFactory(org.apache.log4j.spi.LoggerFactory) Log4jLoggerFactory(org.slf4j.impl.Log4jLoggerFactory)

Aggregations

LoggerFactory (org.apache.log4j.spi.LoggerFactory)2 Appender (org.apache.log4j.Appender)1 FileAppender (org.apache.log4j.FileAppender)1 Logger (org.apache.log4j.Logger)1 PatternLayout (org.apache.log4j.PatternLayout)1 RollingFileAppender (org.apache.log4j.RollingFileAppender)1 Log4jLoggerFactory (org.slf4j.impl.Log4jLoggerFactory)1