use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sonarqube by SonarSource.
the class SearchLoggingTest method log_to_es_file.
@Test
public void log_to_es_file() {
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(ROOT_LOGGER_NAME);
Appender<ILoggingEvent> appender = root.getAppender("file_es");
assertThat(appender).isInstanceOf(FileAppender.class);
FileAppender fileAppender = (FileAppender) appender;
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "es.log").getAbsolutePath());
assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level es[][%logger{20}] %msg%n");
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sling by apache.
the class LogConfigManager method getDefaultAppender.
public Appender<ILoggingEvent> getDefaultAppender() {
OutputStreamAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
appender.setName(DEFAULT_CONSOLE_APPENDER_NAME);
appender.setContext(loggerContext);
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setPattern(LOG_PATTERN_DEFAULT);
encoder.setContext(loggerContext);
encoder.start();
appender.setEncoder(encoder);
appender.start();
return appender;
}
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;
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder 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.classic.encoder.PatternLayoutEncoder in project jlineup by otto-de.
the class Util method logToFile.
static void logToFile(String workingDir) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(lc);
ple.start();
FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
fileAppender.setFile(workingDir + "/jlineup.log");
fileAppender.setEncoder(ple);
fileAppender.setContext(lc);
fileAppender.start();
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
logger.addAppender(fileAppender);
logger.setLevel(Level.DEBUG);
}
Aggregations