Search in sources :

Example 6 with PatternLayoutEncoder

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;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) FixedWindowRollingPolicy(ch.qos.logback.core.rolling.FixedWindowRollingPolicy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 7 with PatternLayoutEncoder

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");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 8 with PatternLayoutEncoder

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");
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) File(java.io.File) Test(org.junit.Test)

Example 9 with PatternLayoutEncoder

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;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 10 with PatternLayoutEncoder

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;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Aggregations

PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)34 LoggerContext (ch.qos.logback.classic.LoggerContext)24 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)23 Logger (ch.qos.logback.classic.Logger)14 FileAppender (ch.qos.logback.core.FileAppender)11 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)10 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)9 Test (org.junit.Test)9 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)8 File (java.io.File)7 FixedWindowRollingPolicy (ch.qos.logback.core.rolling.FixedWindowRollingPolicy)3 Logger (org.slf4j.Logger)3 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)2 Appender (ch.qos.logback.core.Appender)2 SizeBasedTriggeringPolicy (ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy)2 LogcatAppender (ch.qos.logback.classic.android.LogcatAppender)1 RollingPolicy (ch.qos.logback.core.rolling.RollingPolicy)1 BroadcastSession (com.cgbystrom.sockjs.test.BroadcastSession)1 JmxReporter (com.codahale.metrics.JmxReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1