All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.otto.edison.metrics.configuration.Slf4JReporterConfiguration Maven / Gradle / Ivy

There is a newer version: 0.82.2
Show newest version
package de.otto.edison.metrics.configuration;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Slf4jReporter;
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics;
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import static com.codahale.metrics.Slf4jReporter.LoggingLevel.INFO;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.slf4j.LoggerFactory.getLogger;

@Configuration
@EnableMetrics
@ConditionalOnProperty(name = "edison.metrics.slf4j.logger")
public class Slf4JReporterConfiguration extends MetricsConfigurerAdapter {

    @Value("${edison.metrics.slf4j.logger}")
    private String logger;
    @Value("${edison.metrics.slf4j.period:5}")
    private long periodMinutes = 5;

    @Override
    public void configureReporters(final MetricRegistry metricRegistry) {
        Slf4jReporter
                .forRegistry(metricRegistry)
                .outputTo(getLogger(logger))
                .withLoggingLevel(INFO)
                .build()
                .start(periodMinutes, MINUTES);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy