use of ch.qos.logback.classic.encoder.PatternLayoutEncoder 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.classic.encoder.PatternLayoutEncoder 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.classic.encoder.PatternLayoutEncoder 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