Search in sources :

Example 1 with PatternLayoutEncoder

use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project jmxtrans by jmxtrans.

the class TimeBasedRollingKeyOutWriter method buildEncoder.

protected Encoder buildEncoder() {
    PatternLayoutEncoder logEncoder = new PatternLayoutEncoder();
    logEncoder.setContext(loggerContext);
    logEncoder.setPattern(getSettingOutputPattern());
    logEncoder.start();
    return logEncoder;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder)

Example 2 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 3 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 4 with PatternLayoutEncoder

use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project BIMserver by opensourceBIM.

the class JarBimServer method fixLogging.

/**
 * Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
 *
 * @throws IOException
 */
private void fixLogging(BimServerConfig config) throws IOException {
    Path logFolder = config.getHomeDir().resolve("logs");
    if (!Files.isDirectory(logFolder)) {
        Files.createDirectories(logFolder);
    }
    Path file = logFolder.resolve("bimserver.log");
    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<ILoggingEvent>();
    String filename = file.toAbsolutePath().toString();
    if (lc instanceof LoggerContext) {
        if (!lc.isStarted()) {
            lc.start();
        }
    }
    System.out.println("Logging to " + filename);
    fileAppender.setFile(filename);
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();
    for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
        if (log.getLevel() != null) {
            log.addAppender(fileAppender);
        }
    }
}
Also used : Path(java.nio.file.Path) 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 5 with PatternLayoutEncoder

use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project BIMserver by opensourceBIM.

the class LocalDevBimServerStarter method fixLogging.

/**
 * Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
 *
 * @throws IOException
 */
private void fixLogging(BimServerConfig config) throws IOException {
    Path logFolder = config.getHomeDir().resolve("logs");
    if (!Files.isDirectory(logFolder)) {
        Files.createDirectories(logFolder);
    }
    Path file = logFolder.resolve("bimserver.log");
    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<ILoggingEvent>();
    String filename = file.toAbsolutePath().toString();
    if (lc instanceof LoggerContext) {
        if (!lc.isStarted()) {
            lc.start();
        }
    }
    System.out.println("Logging to " + filename);
    fileAppender.setFile(filename);
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();
    for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
        if (log.getLevel() != null) {
            log.addAppender(fileAppender);
        }
    }
}
Also used : Path(java.nio.file.Path) 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)

Aggregations

PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)64 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)43 LoggerContext (ch.qos.logback.classic.LoggerContext)36 Logger (ch.qos.logback.classic.Logger)20 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)20 FileAppender (ch.qos.logback.core.FileAppender)20 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)17 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)13 File (java.io.File)10 Test (org.junit.Test)10 Logger (org.slf4j.Logger)6 Appender (ch.qos.logback.core.Appender)5 SizeBasedTriggeringPolicy (ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy)5 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)4 FixedWindowRollingPolicy (ch.qos.logback.core.rolling.FixedWindowRollingPolicy)4 Path (java.nio.file.Path)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