Search in sources :

Example 26 with FileAppender

use of ch.qos.logback.core.FileAppender in project sonarqube by SonarSource.

the class CeProcessLoggingTest method log_to_ce_file.

@Test
public void log_to_ce_file() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
    Appender<ILoggingEvent> appender = root.getAppender("file_ce");
    assertThat(appender).isInstanceOf(FileAppender.class);
    FileAppender fileAppender = (FileAppender) appender;
    assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "ce.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 ce[%X{ceTaskUuid}][%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 27 with FileAppender

use of ch.qos.logback.core.FileAppender 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 28 with FileAppender

use of ch.qos.logback.core.FileAppender in project sling by apache.

the class SlingLogPanel method renderAppenderContent.

private void renderAppenderContent(LoggerStateContext ctx, PrintWriter pw, String appenderName, TailerOptions opts) throws IOException {
    for (final Appender<ILoggingEvent> appender : ctx.appenders.values()) {
        if (appender instanceof FileAppender && appenderName.equals(appender.getName())) {
            final File file = new File(((FileAppender) appender).getFile());
            if (file.exists()) {
                if (opts.tailAll()) {
                    SlingConfigurationPrinter.includeWholeFile(pw, file);
                } else {
                    int numOfLines = opts.getNumOfLines();
                    if (numOfLines == 0) {
                        numOfLines = logbackManager.getLogConfigManager().getNumOfLines();
                    }
                    new Tailer(new FilteringListener(pw, opts.getRegex()), numOfLines).tail(file);
                }
            }
            return;
        }
    }
    pw.printf("No appender with name [%s] found", appenderName);
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) SlingRollingFileAppender(org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File)

Example 29 with FileAppender

use of ch.qos.logback.core.FileAppender in project sling by apache.

the class LogTailerWebConsolePlugin method getOptions.

private String getOptions() {
    Set<String> logFiles = new HashSet<String>();
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext(); ) {
            Appender<ILoggingEvent> appender = index.next();
            if (appender instanceof FileAppender) {
                FileAppender fileAppender = (FileAppender) appender;
                String logfilePath = fileAppender.getFile();
                logFiles.add(logfilePath);
            }
        }
    }
    String logFilesHtml = "<option value=\"\"> - Select file - </option>";
    for (String logFile : logFiles) {
        File file = new File(logFile);
        logFilesHtml += "<option value=\"" + getKey(file) + "\">" + file.getName() + "</option>";
    }
    return logFilesHtml;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 30 with FileAppender

use of ch.qos.logback.core.FileAppender in project qpid-broker-j by apache.

the class RollingPolicyDecoratorTest method testSetParent.

public void testSetParent() {
    FileAppender appender = mock(FileAppender.class);
    _policy.setParent(appender);
    verify(_delegate).setParent(appender);
}
Also used : FileAppender(ch.qos.logback.core.FileAppender)

Aggregations

FileAppender (ch.qos.logback.core.FileAppender)46 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)33 LoggerContext (ch.qos.logback.classic.LoggerContext)27 File (java.io.File)23 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)18 Logger (ch.qos.logback.classic.Logger)17 Appender (ch.qos.logback.core.Appender)14 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)12 Test (org.junit.Test)9 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)6 Path (java.nio.file.Path)6 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)5 FileSize (ch.qos.logback.core.util.FileSize)5 Test (org.junit.jupiter.api.Test)5 FixedWindowRollingPolicy (ch.qos.logback.core.rolling.FixedWindowRollingPolicy)4 SizeBasedTriggeringPolicy (ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy)4 IOException (java.io.IOException)4 Field (java.lang.reflect.Field)4 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)3 SizeAndTimeBasedRollingPolicy (ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy)3