Search in sources :

Example 1 with Appender

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

the class SearchLoggingTest method do_not_log_to_console.

@Test
public void do_not_log_to_console() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(ROOT_LOGGER_NAME);
    Appender appender = root.getAppender("CONSOLE");
    assertThat(appender).isNull();
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 2 with Appender

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

the class ITDefaultConfig method testDefaultSettings.

/**
     * Checks the default settings. It runs the bundle with minimum dependencies
     */
@Test
public void testDefaultSettings() throws Exception {
    Logger slf4jLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    assertTrue("Default Log level should be INFO", slf4jLogger.isInfoEnabled());
    // Check for Logback being used
    assertTrue(LoggerFactory.getILoggerFactory() instanceof LoggerContext);
    assertTrue(slf4jLogger instanceof ch.qos.logback.classic.Logger);
    // Test that root logger has one FileAppender attached
    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) slf4jLogger;
    Iterator<Appender<ILoggingEvent>> itr = logger.iteratorForAppenders();
    assertTrue("One appender should be attached with root logger", itr.hasNext());
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 3 with Appender

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

the class ITConfigAdminSupport method testChangeLogLevelWithConfig.

@Test
public void testChangeLogLevelWithConfig() throws Exception {
    // Set log level to debug for foo1.bar
    Configuration config = ca.createFactoryConfiguration(FACTORY_PID_CONFIGS, null);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put(LOG_LOGGERS, new String[] { "foo1.bar" });
    p.put(LOG_LEVEL, "DEBUG");
    config.update(p);
    delay();
    Logger slf4jLogger = LoggerFactory.getLogger("foo1.bar");
    assertTrue(slf4jLogger.isDebugEnabled());
    assertTrue(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isInfoEnabled());
    assertFalse(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).isDebugEnabled());
    // foo1.bar should not have explicit appender attached with it
    Iterator<Appender<ILoggingEvent>> itr = ((ch.qos.logback.classic.Logger) slf4jLogger).iteratorForAppenders();
    assertFalse(itr.hasNext());
}
Also used : Appender(ch.qos.logback.core.Appender) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 4 with Appender

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

use of ch.qos.logback.core.Appender 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

Appender (ch.qos.logback.core.Appender)117 Test (org.junit.Test)62 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)50 LoggerContext (ch.qos.logback.classic.LoggerContext)32 Logger (ch.qos.logback.classic.Logger)31 FileAppender (ch.qos.logback.core.FileAppender)27 Logger (org.slf4j.Logger)25 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)21 ArgumentMatcher (org.mockito.ArgumentMatcher)19 AsyncAppender (ch.qos.logback.classic.AsyncAppender)18 File (java.io.File)14 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13 LogstashTcpSocketAppender (net.logstash.logback.appender.LogstashTcpSocketAppender)13 ArrayList (java.util.ArrayList)11 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)11 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)9 DBAppender (ch.qos.logback.classic.db.DBAppender)8 Test (org.junit.jupiter.api.Test)7