use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sonarqube by SonarSource.
the class LogbackHelper method newFileAppender.
public FileAppender<ILoggingEvent> newFileAppender(LoggerContext ctx, Props props, RootLoggerConfig config, String logPattern) {
RollingPolicy rollingPolicy = createRollingPolicy(ctx, props, config.getProcessId().getLogFilenamePrefix());
FileAppender<ILoggingEvent> fileAppender = rollingPolicy.createAppender("file_" + config.getProcessId().getLogFilenamePrefix());
fileAppender.setContext(ctx);
PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
fileEncoder.setContext(ctx);
fileEncoder.setPattern(logPattern);
fileEncoder.start();
fileAppender.setEncoder(fileEncoder);
fileAppender.start();
return fileAppender;
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sonarqube by SonarSource.
the class WebServerProcessLoggingTest method startup_logger_prints_to_only_to_system_out.
@Test
public void startup_logger_prints_to_only_to_system_out() {
LoggerContext ctx = underTest.configure(props);
Logger startup = ctx.getLogger("startup");
assertThat(startup.isAdditive()).isFalse();
Appender appender = startup.getAppender("CONSOLE");
assertThat(appender).isInstanceOf(ConsoleAppender.class);
ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project sonarqube by SonarSource.
the class WebServerProcessLoggingTest method log_to_web_file.
@Test
public void log_to_web_file() {
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
Appender<ILoggingEvent> appender = root.getAppender("file_web");
assertThat(appender).isInstanceOf(FileAppender.class);
FileAppender fileAppender = (FileAppender) appender;
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "web.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 web[%X{HTTP_REQUEST_ID}][%logger{20}] %msg%n");
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project openhab1-addons by openhab.
the class LoggingPersistenceService method createNewAppender.
protected FileAppender<ILoggingEvent> createNewAppender(String alias) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(pattern);
encoder.start();
FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
appender.setAppend(true);
appender.setFile(LOG_FOLDER + File.separator + alias + LOG_FILEEXT);
appender.setEncoder(encoder);
appender.setContext(context);
appender.start();
return appender;
}
use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project spring-boot by spring-projects.
the class DefaultLogbackConfiguration method fileAppender.
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config, String logFile) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("file", FILE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
appender.setEncoder(encoder);
config.start(encoder);
appender.setFile(logFile);
setRollingPolicy(appender, config, logFile);
setMaxFileSize(appender, config);
config.appender("FILE", appender);
return appender;
}
Aggregations