Search in sources :

Example 41 with PatternLayoutEncoder

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");
}
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 42 with PatternLayoutEncoder

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

Example 43 with PatternLayoutEncoder

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

Example 44 with PatternLayoutEncoder

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);*/
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) FixedWindowRollingPolicy(ch.qos.logback.core.rolling.FixedWindowRollingPolicy) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) SizeBasedTriggeringPolicy(ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 45 with PatternLayoutEncoder

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

Aggregations

PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)69 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)46 LoggerContext (ch.qos.logback.classic.LoggerContext)39 FileAppender (ch.qos.logback.core.FileAppender)21 Logger (ch.qos.logback.classic.Logger)20 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)20 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)18 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)13 File (java.io.File)10 Test (org.junit.Test)10 Logger (org.slf4j.Logger)9 SizeBasedTriggeringPolicy (ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy)6 Appender (ch.qos.logback.core.Appender)5 FixedWindowRollingPolicy (ch.qos.logback.core.rolling.FixedWindowRollingPolicy)5 Path (java.nio.file.Path)5 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)4 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)3 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)3 RollingPolicy (ch.qos.logback.core.rolling.RollingPolicy)3 Encoder (ch.qos.logback.core.encoder.Encoder)2