Search in sources :

Example 21 with Logger

use of ch.qos.logback.classic.Logger in project sling by apache.

the class OsgiAppenderRefInternalAction method begin.

@Override
public void begin(InterpretationContext ec, String tagName, Attributes attributes) throws ActionException {
    // Let us forget about previous errors (in this object)
    inError = false;
    Object o = ec.peekObject();
    if (!(o instanceof Logger)) {
        String errMsg = "Could not find an Logger at the top of execution stack. Near [" + tagName + "] line " + getLineNumber(ec);
        inError = true;
        addError(errMsg);
        return;
    }
    Logger logger = (Logger) o;
    String appenderName = ec.subst(attributes.getValue(ActionConst.REF_ATTRIBUTE));
    if (OptionHelper.isEmpty(appenderName)) {
        // print a meaningful error message and return
        String errMsg = "Missing appender ref attribute in <appender-ref> tag.";
        inError = true;
        addError(errMsg);
        return;
    }
    @SuppressWarnings("unchecked") Map<String, Set<String>> appenderBag = (Map<String, Set<String>>) ec.getObjectMap().get(OSGI_APPENDER_REF_BAG);
    if (appenderBag == null) {
        appenderBag = new HashMap<String, Set<String>>();
        ec.getObjectMap().put(OSGI_APPENDER_REF_BAG, appenderBag);
    }
    Set<String> loggers = appenderBag.get(appenderName);
    if (loggers == null) {
        loggers = new HashSet<String>();
        appenderBag.put(appenderName, loggers);
    }
    loggers.add(logger.getName());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Logger(ch.qos.logback.classic.Logger) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with Logger

use of ch.qos.logback.classic.Logger in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method resetLogging.

@Before
public void resetLogging() {
    LoggerContext loggerContext = ((Logger) LoggerFactory.getLogger(getClass())).getLoggerContext();
    loggerContext.reset();
    new BasicConfigurator().configure(loggerContext);
}
Also used : BasicConfigurator(ch.qos.logback.classic.BasicConfigurator) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Before(org.junit.Before)

Example 23 with Logger

use of ch.qos.logback.classic.Logger in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method clear.

@Before
public void clear() {
    storage.clear();
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    when(mockAppender.getName()).thenReturn(CassandraSpanConsumerTest.class.getName());
    root.addAppender(mockAppender);
}
Also used : Logger(ch.qos.logback.classic.Logger) Before(org.junit.Before)

Example 24 with Logger

use of ch.qos.logback.classic.Logger in project felix by apache.

the class Common method config.

@Configuration
public Option[] config() throws IOException {
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.DEBUG);
    return options(cleanCaches(), ipojoBundles(), junitBundles(), testedBundle(), systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"));
}
Also used : Logger(ch.qos.logback.classic.Logger) Configuration(org.ops4j.pax.exam.Configuration)

Example 25 with Logger

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

the class SonarLintLogging method setCustomRootAppender.

private static void setCustomRootAppender(Appender<ILoggingEvent> defaultAppender) {
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    // by default it has an appender logging to stdout
    logger.detachAndStopAllAppenders();
    appender = new LogCallbackAppender(defaultAppender);
    appender.setName(CUSTOM_APPENDER_NAME);
    appender.start();
    logger.addAppender(appender);
}
Also used : Logger(ch.qos.logback.classic.Logger)

Aggregations

Logger (ch.qos.logback.classic.Logger)339 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)90 LoggerContext (ch.qos.logback.classic.LoggerContext)86 Test (org.junit.Test)78 Appender (ch.qos.logback.core.Appender)30 BeforeClass (org.junit.BeforeClass)28 FileAppender (ch.qos.logback.core.FileAppender)27 Test (org.junit.jupiter.api.Test)27 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)22 File (java.io.File)21 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)20 Level (ch.qos.logback.classic.Level)18 ListAppender (ch.qos.logback.core.read.ListAppender)14 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)12 ArrayList (java.util.ArrayList)11 Before (org.junit.Before)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 Map (java.util.Map)10 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)9 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)8