Search in sources :

Example 16 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project uavstack by uavorg.

the class LogBackHookProxy method figureoutLogConfiguration.

private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
    Iterator<Appender<ILoggingEvent>> appenders = Logger.iteratorForAppenders();
    while (appenders != null && appenders.hasNext()) {
        LogProfileInfo logProfileInfo = new LogProfileInfo();
        if (appid != null) {
            logProfileInfo.setAppId(appid);
        }
        logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(LogProfileInfo.ENGINE, "logback");
        Appender<ILoggingEvent> appender = appenders.next();
        if (!(appender instanceof FileAppender<?>)) {
            continue;
        }
        FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
        @SuppressWarnings("rawtypes") LayoutWrappingEncoder encoder = (LayoutWrappingEncoder) fileAppender.getEncoder();
        Layout<?> layout = encoder.getLayout();
        if (null != layout) {
            if (layout instanceof PatternLayout) {
                PatternLayout patternLayout = (PatternLayout) encoder.getLayout();
                attributes.put(LogProfileInfo.PATTERN, patternLayout.getPattern());
            } else if (layout instanceof HTMLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
            } else if (layout instanceof XMLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "XMLLayout");
            } else if (layout instanceof TTLLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
            }
        }
        logProfileInfo.setFilePath(fileAppender.getFile());
        logProfileInfo.setAttributes(attributes);
        list.add(logProfileInfo);
    }
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) HashMap(java.util.HashMap) HTMLLayout(ch.qos.logback.classic.html.HTMLLayout) PatternLayout(ch.qos.logback.classic.PatternLayout) TTLLLayout(ch.qos.logback.classic.layout.TTLLLayout) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) XMLLayout(ch.qos.logback.classic.log4j.XMLLayout) LayoutWrappingEncoder(ch.qos.logback.core.encoder.LayoutWrappingEncoder)

Example 17 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent 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)

Example 18 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarlint-core by SonarSource.

the class SonarLintLogging method init.

private static void init() {
    ConsoleAppender<ILoggingEvent> defaultAppender = new ConsoleAppender<>();
    defaultAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
    defaultAppender.setName(DEFAULT_APPENDER_NAME);
    LevelFilter levelFilter = new LevelFilter();
    levelFilter.setLevel(Level.ERROR);
    defaultAppender.addFilter(levelFilter);
    // if output is not set for thread, keep default behavior (configured to stdout)
    setCustomRootAppender(defaultAppender);
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) LevelFilter(ch.qos.logback.classic.filter.LevelFilter) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 19 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project qpid-broker-j by apache.

the class VirtualHostNameAndLevelLogInclusionRuleImplTest method testAsFilter.

public void testAsFilter() {
    VirtualHostNameAndLevelLogInclusionRule<?> rule = createRule("org.apache.qpid", LogLevel.INFO);
    Filter<ILoggingEvent> filter = rule.asFilter();
    assertTrue("Unexpected filter instance", filter instanceof LoggerNameAndLevelFilter);
    LoggerNameAndLevelFilter f = (LoggerNameAndLevelFilter) filter;
    assertEquals("Unexpected log level", Level.INFO, f.getLevel());
    assertEquals("Unexpected logger name", "org.apache.qpid", f.getLoggerName());
}
Also used : LoggerNameAndLevelFilter(org.apache.qpid.server.logging.logback.LoggerNameAndLevelFilter) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 20 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project qpid-broker-j by apache.

the class QpidBrokerTestCase method getFileFromSiftingAppender.

private File getFileFromSiftingAppender(final ch.qos.logback.classic.Logger logger) {
    String key = logger.getLoggerContext().getProperty(LogbackPropertyValueDiscriminator.CLASS_QUALIFIED_TEST_NAME);
    for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext(); ) /* do nothing */
    {
        Appender<ILoggingEvent> appender = index.next();
        if (appender instanceof SiftingAppender) {
            SiftingAppender siftingAppender = (SiftingAppender) appender;
            Appender subAppender = siftingAppender.getAppenderTracker().find(key);
            if (subAppender instanceof FileAppender) {
                return new File(((FileAppender) subAppender).getFile());
            }
        }
    }
    return null;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) SiftingAppender(ch.qos.logback.classic.sift.SiftingAppender) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File) SiftingAppender(ch.qos.logback.classic.sift.SiftingAppender)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)300 Test (org.junit.Test)111 Logger (ch.qos.logback.classic.Logger)90 LoggerContext (ch.qos.logback.classic.LoggerContext)85 Appender (ch.qos.logback.core.Appender)48 Test (org.junit.jupiter.api.Test)47 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)44 FileAppender (ch.qos.logback.core.FileAppender)40 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)35 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)30 File (java.io.File)26 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)22 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)21 Logger (org.slf4j.Logger)20 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)17 AsyncAppender (ch.qos.logback.classic.AsyncAppender)16 ArrayList (java.util.ArrayList)16 ListAppender (ch.qos.logback.core.read.ListAppender)15 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13