de.otto.edison.metrics.configuration.Slf4JReporterConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edison-metrics Show documentation
Show all versions of edison-metrics Show documentation
Status library of the edison-microservice project.
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);
}
}