use of ch.qos.logback.core.rolling.RollingFileAppender in project bitsquare by bitsquare.
the class Log method setup.
public static void setup(String fileName) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender appender = new RollingFileAppender();
appender.setContext(loggerContext);
appender.setFile(fileName + ".log");
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(appender);
rollingPolicy.setFileNamePattern(fileName + "_%i.log");
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(10);
rollingPolicy.start();
triggeringPolicy = new SizeBasedTriggeringPolicy();
triggeringPolicy.setMaxFileSize(FileSize.valueOf("10MB"));
triggeringPolicy.start();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n");
encoder.start();
appender.setEncoder(encoder);
appender.setRollingPolicy(rollingPolicy);
appender.setTriggeringPolicy(triggeringPolicy);
appender.start();
logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
logbackLogger.addAppender(appender);
logbackLogger.setLevel(Level.INFO);
// log errors in separate file
// not working as expected still.... damn logback...
/* FileAppender errorAppender = new FileAppender();
errorAppender.setEncoder(encoder);
errorAppender.setName("Error");
errorAppender.setContext(loggerContext);
errorAppender.setFile(fileName + "_error.log");
LevelFilter levelFilter = new LevelFilter();
levelFilter.setLevel(Level.ERROR);
levelFilter.setOnMatch(FilterReply.ACCEPT);
levelFilter.setOnMismatch(FilterReply.DENY);
levelFilter.start();
errorAppender.addFilter(levelFilter);
errorAppender.start();
logbackLogger.addAppender(errorAppender);*/
}
use of ch.qos.logback.core.rolling.RollingFileAppender in project cdap-ingest by caskdata.
the class FileTailerMetricsProcessor method initAppender.
/**
* Initializes the file appender.
*
* @param path the path to the directory for the metrics file
* @param fileName the name of the metrics file
* @return the initialized file appender
*/
private RollingFileAppender initAppender(String path, String fileName) {
LOG.debug("Starting initialize rolling file appender");
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setContext(loggerContext);
fileAppender.setFile(path + "/" + fileName);
fileAppender.setAppend(true);
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern(path + "/" + fileName + ".%d");
rollingPolicy.start();
fileAppender.setRollingPolicy(rollingPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("%msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
return fileAppender;
}
use of ch.qos.logback.core.rolling.RollingFileAppender in project cdap-ingest by caskdata.
the class TailerLogUtils method getTimeLogger.
public static Logger getTimeLogger(String file) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setContext(loggerContext);
fileAppender.setFile(file);
fileAppender.setAppend(true);
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern(file + "%d{yyyy-MM-dd_HH-mm}");
rollingPolicy.start();
fileAppender.setRollingPolicy(rollingPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("[%d %-5p %c{1}] %msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
// configures the root logger
Logger rootLogger = loggerContext.getLogger(BaseTailerTest.class.getName() + "time");
rootLogger.setLevel(Level.DEBUG);
rootLogger.addAppender(fileAppender);
return rootLogger;
}
use of ch.qos.logback.core.rolling.RollingFileAppender in project coffeenet-starter by coffeenet.
the class CoffeeNetLoggingAutoConfiguration method rollingFileAppender.
private RollingFileAppender<ILoggingEvent> rollingFileAppender(LoggerContext loggerContext) {
RollingFileAppender<ILoggingEvent> rfAppender = new RollingFileAppender<>();
rfAppender.setName(COFFEENET_FILE_APPENDER);
rfAppender.setContext(loggerContext);
rfAppender.setFile(coffeeNetLoggingFileProperties.getFile());
// TimeBasedRollingPolicy
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(rfAppender);
rollingPolicy.setFileNamePattern(coffeeNetLoggingFileProperties.getFileNamePattern());
rollingPolicy.setMaxHistory(coffeeNetLoggingFileProperties.getMaxHistory());
rollingPolicy.start();
rfAppender.setRollingPolicy(rollingPolicy);
// PatternLayoutEncoder
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern(coffeeNetLoggingFileProperties.getPattern());
encoder.start();
rfAppender.setEncoder(encoder);
rfAppender.start();
return rfAppender;
}
Aggregations