Search in sources :

Example 1 with InstrumentedAppender

use of com.codahale.metrics.log4j2.InstrumentedAppender in project graylog2-server by Graylog2.

the class CmdLineTool method addInstrumentedAppender.

private void addInstrumentedAppender(final MetricRegistry metrics, final Level level) {
    final InstrumentedAppender appender = new InstrumentedAppender(metrics, null, null, false);
    appender.start();
    final LoggerContext context = (LoggerContext) LogManager.getContext(false);
    final org.apache.logging.log4j.core.config.Configuration config = context.getConfiguration();
    config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, level, null);
    context.updateLoggers(config);
}
Also used : InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 2 with InstrumentedAppender

use of com.codahale.metrics.log4j2.InstrumentedAppender in project curiostack by curioswitch.

the class MonitoringModule method configureLogMetrics.

private static void configureLogMetrics() {
    InstrumentedAppender appender = InstrumentedAppender.createAppender("PROMETHEUS");
    appender.start();
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();
    config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, null, null);
    context.updateLoggers(config);
}
Also used : InstrumentedAppender(io.prometheus.client.log4j2.InstrumentedAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 3 with InstrumentedAppender

use of com.codahale.metrics.log4j2.InstrumentedAppender in project metrics by dropwizard.

the class InstrumentedAppenderTest method usesSharedRegistries.

@Test
public void usesSharedRegistries() throws Exception {
    String registryName = "registry";
    SharedMetricRegistries.add(registryName, registry);
    final InstrumentedAppender shared = new InstrumentedAppender(registryName);
    shared.start();
    when(event.getLevel()).thenReturn(Level.INFO);
    shared.append(event);
    assertThat(registry.meter(METRIC_NAME_PREFIX + ".info").getCount()).isEqualTo(1);
}
Also used : InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) Test(org.junit.Test)

Aggregations

InstrumentedAppender (com.codahale.metrics.log4j2.InstrumentedAppender)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 InstrumentedAppender (io.prometheus.client.log4j2.InstrumentedAppender)1 Configuration (org.apache.logging.log4j.core.config.Configuration)1 Test (org.junit.Test)1