Fork me on GitHub

Instrumenting Logback

The metrics-logback module provides InstrumentedAppender, a Logback Appender implementation which records the rate of logged events by their logging level.

You can either add it to the root logger programmatically:

final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);

final InstrumentedAppender metrics = new InstrumentedAppender();

Or you can add it via Logback’s XML configuration:

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>

    <appender name="metrics" class="com.yammer.metrics.logback.InstrumentedAppender"/>

    <root level="DEBUG">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="metrics"/>