Search in sources :

Example 71 with Logger

use of ch.qos.logback.classic.Logger in project dropwizard by dropwizard.

the class DefaultLoggingFactory method reset.

@Override
public void reset() {
    CHANGE_LOGGER_CONTEXT_LOCK.lock();
    try {
        // Flush all the loggers and reinstate only the console logger as a
        // sane default.
        loggerContext.stop();
        final Logger logger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
        logger.detachAndStopAllAppenders();
        logger.addAppender(new ConsoleAppender<>());
        loggerContext.start();
    } finally {
        CHANGE_LOGGER_CONTEXT_LOCK.unlock();
    }
}
Also used : Logger(ch.qos.logback.classic.Logger)

Example 72 with Logger

use of ch.qos.logback.classic.Logger in project dropwizard by dropwizard.

the class DefaultLoggingFactory method configure.

@Override
public void configure(MetricRegistry metricRegistry, String name) {
    LoggingUtil.hijackJDKLogging();
    CHANGE_LOGGER_CONTEXT_LOCK.lock();
    final Logger root;
    try {
        root = configureLoggers(name);
    } finally {
        CHANGE_LOGGER_CONTEXT_LOCK.unlock();
    }
    final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new ThresholdLevelFilterFactory();
    final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
    final LayoutFactory<ILoggingEvent> layoutFactory = new DropwizardLayoutFactory();
    for (AppenderFactory<ILoggingEvent> output : appenders) {
        root.addAppender(output.build(loggerContext, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    StatusPrinter.setPrintStream(configurationErrorsStream);
    try {
        StatusPrinter.printIfErrorsOccured(loggerContext);
    } finally {
        StatusPrinter.setPrintStream(System.out);
    }
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    MBEAN_REGISTRATION_LOCK.lock();
    try {
        final ObjectName objectName = new ObjectName("io.dropwizard:type=Logging");
        if (!server.isRegistered(objectName)) {
            server.registerMBean(new JMXConfigurator(loggerContext, server, objectName), objectName);
        }
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | NotCompliantMBeanException | MBeanRegistrationException e) {
        throw new RuntimeException(e);
    } finally {
        MBEAN_REGISTRATION_LOCK.unlock();
    }
    configureInstrumentation(root, metricRegistry);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ThresholdLevelFilterFactory(io.dropwizard.logging.filter.ThresholdLevelFilterFactory) ObjectName(javax.management.ObjectName) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) JMXConfigurator(ch.qos.logback.classic.jmx.JMXConfigurator) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer)

Example 73 with Logger

use of ch.qos.logback.classic.Logger in project dropwizard by dropwizard.

the class LogbackClassicRequestLogFactory method build.

public RequestLog build(String name) {
    final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
    logger.setAdditive(false);
    final LoggerContext context = logger.getLoggerContext();
    final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new NullLevelFilterFactory<>();
    final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
    final LayoutFactory<ILoggingEvent> layoutFactory = (c, tz) -> new RequestLogLayout();
    final AppenderAttachableImpl<ILoggingEvent> attachable = new AppenderAttachableImpl<>();
    for (AppenderFactory<ILoggingEvent> appender : appenders) {
        attachable.addAppender(appender.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    return new DropwizardSlf4jRequestLog(attachable, timeZone);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ConsoleAppenderFactory(io.dropwizard.logging.ConsoleAppenderFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerFactory(org.slf4j.LoggerFactory) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Valid(javax.validation.Valid) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) RequestLogFactory(io.dropwizard.request.logging.RequestLogFactory) ImmutableList(com.google.common.collect.ImmutableList) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) CoreConstants(ch.qos.logback.core.CoreConstants) PatternLayoutBase(ch.qos.logback.core.pattern.PatternLayoutBase) AppenderAttachableImpl(ch.qos.logback.core.spi.AppenderAttachableImpl) RequestLog(org.eclipse.jetty.server.RequestLog) ImmutableMap(com.google.common.collect.ImmutableMap) LayoutFactory(io.dropwizard.logging.layout.LayoutFactory) TimeZone(java.util.TimeZone) AppenderFactory(io.dropwizard.logging.AppenderFactory) LevelFilterFactory(io.dropwizard.logging.filter.LevelFilterFactory) NotNull(javax.validation.constraints.NotNull) Logger(ch.qos.logback.classic.Logger) AsyncAppenderFactory(io.dropwizard.logging.async.AsyncAppenderFactory) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) AppenderAttachableImpl(ch.qos.logback.core.spi.AppenderAttachableImpl) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)

Example 74 with Logger

use of ch.qos.logback.classic.Logger in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method appenderNameIsSet.

@Test
public void appenderNameIsSet() throws Exception {
    final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    final ConsoleAppenderFactory<ILoggingEvent> appenderFactory = new ConsoleAppenderFactory<>();
    final Appender<ILoggingEvent> appender = appenderFactory.build(root.getLoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(appender.getName()).isEqualTo("async-console-appender");
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 75 with Logger

use of ch.qos.logback.classic.Logger in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method appenderContextIsSet.

@Test
public void appenderContextIsSet() throws Exception {
    final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    final ConsoleAppenderFactory<ILoggingEvent> appenderFactory = new ConsoleAppenderFactory<>();
    final Appender<ILoggingEvent> appender = appenderFactory.build(root.getLoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(appender.getContext()).isEqualTo(root.getLoggerContext());
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Aggregations

Logger (ch.qos.logback.classic.Logger)144 Test (org.junit.Test)49 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)45 LoggerContext (ch.qos.logback.classic.LoggerContext)40 FileAppender (ch.qos.logback.core.FileAppender)17 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)16 Appender (ch.qos.logback.core.Appender)16 File (java.io.File)13 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 ArrayList (java.util.ArrayList)9 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)8 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)8 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)7 Before (org.junit.Before)7 PipeConfiguration (co.cask.cdap.filetailer.config.PipeConfiguration)6 Query (org.apache.lucene.search.Query)6 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)6 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)6 Level (ch.qos.logback.classic.Level)5 Map (java.util.Map)5