Slf4jReporter extends ScheduledReporter { @Override @SuppressWarnings("rawtypes") public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { if (loggerProxy.isEnabled(marker)) { StringBuilder b = new StringBuilder(); for (Entry<String, Gauge> entry : gauges.entrySet()) { logGauge(b, entry.getKey(), entry.getValue()); } for (Entry<String, Counter> entry : counters.entrySet()) { logCounter(b, entry.getKey(), entry.getValue()); } for (Entry<String, Histogram> entry : histograms.entrySet()) { logHistogram(b, entry.getKey(), entry.getValue()); } for (Entry<String, Meter> entry : meters.entrySet()) { logMeter(b, entry.getKey(), entry.getValue()); } for (Entry<String, Timer> entry : timers.entrySet()) { logTimer(b, entry.getKey(), entry.getValue()); } } } private  Slf4jReporter(MetricRegistry registry,
                          LoggerProxy loggerProxy,
                          Marker marker,
                          String prefix,
                          TimeUnit rateUnit,
                          TimeUnit durationUnit,
                          MetricFilter filter,
                          ScheduledExecutorService executor,
                          boolean shutdownExecutorOnStop,
                          Set<MetricAttribute> disabledMetricAttributes); static Builder forRegistry(MetricRegistry registry); @Override @SuppressWarnings("rawtypes") void report(SortedMap<String, Gauge> gauges,
                       SortedMap<String, Counter> counters,
                       SortedMap<String, Histogram> histograms,
                       SortedMap<String, Meter> meters,
                       SortedMap<String, Timer> timers);  }
@Test public void reportsGaugeValuesDefault() { when(logger.isInfoEnabled(marker)).thenReturn(true); infoReporter().report(map("gauge", () -> "value"), map(), map(), map(), map()); verify(logger).info(marker, "type=GAUGE, name=prefix.gauge, value=value"); }
@Test public void reportsCounterValuesDefault() { final Counter counter = counter(); when(logger.isInfoEnabled(marker)).thenReturn(true); infoReporter().report(map(), map("test.counter", counter), map(), map(), map()); verify(logger).info(marker, "type=COUNTER, name=prefix.test.counter, count=100"); }
@Test public void reportsHistogramValuesDefault() { final Histogram histogram = histogram(); when(logger.isInfoEnabled(marker)).thenReturn(true); infoReporter().report(map(), map(), map("test.histogram", histogram), map(), map()); verify(logger).info(marker, "type=HISTOGRAM, name=prefix.test.histogram, count=1, min=4, max=2, mean=3.0, " + "stddev=5.0, p50=6.0, p75=7.0, p95=8.0, p98=9.0, p99=10.0, p999=11.0"); }
@Test public void reportsMeterValuesDefault() { final Meter meter = meter(); when(logger.isInfoEnabled(marker)).thenReturn(true); infoReporter().report(map(), map(), map(), map("test.meter", meter), map()); verify(logger).info(marker, "type=METER, name=prefix.test.meter, count=1, m1_rate=3.0, m5_rate=4.0, " + "m15_rate=5.0, mean_rate=2.0, rate_unit=events/second"); }
@Test public void reportsTimerValuesDefault() { final Timer timer = timer(); when(logger.isInfoEnabled(marker)).thenReturn(true); infoReporter().report(map(), map(), map(), map(), map("test.another.timer", timer)); verify(logger).info(marker, "type=TIMER, name=prefix.test.another.timer, count=1, min=300.0, max=100.0, " + "mean=200.0, stddev=400.0, p50=500.0, p75=600.0, p95=700.0, p98=800.0, p99=900.0, p999=1000.0," + " m1_rate=3.0, m5_rate=4.0, m15_rate=5.0, mean_rate=2.0, rate_unit=events/second, duration_unit=milliseconds"); }
@Test public void reportsAllMetricsDefault() { when(logger.isInfoEnabled(marker)).thenReturn(true); infoReporter().report(map("test.gauge", () -> "value"), map("test.counter", counter()), map("test.histogram", histogram()), map("test.meter", meter()), map("test.timer", timer())); verify(logger).info(marker, "type=GAUGE, name=prefix.test.gauge, value=value"); verify(logger).info(marker, "type=COUNTER, name=prefix.test.counter, count=100"); verify(logger).info(marker, "type=HISTOGRAM, name=prefix.test.histogram, count=1, min=4, max=2, mean=3.0, " + "stddev=5.0, p50=6.0, p75=7.0, p95=8.0, p98=9.0, p99=10.0, p999=11.0"); verify(logger).info(marker, "type=METER, name=prefix.test.meter, count=1, m1_rate=3.0, m5_rate=4.0, " + "m15_rate=5.0, mean_rate=2.0, rate_unit=events/second"); verify(logger).info(marker, "type=TIMER, name=prefix.test.timer, count=1, min=300.0, max=100.0, " + "mean=200.0, stddev=400.0, p50=500.0, p75=600.0, p95=700.0, p98=800.0, p99=900.0, p999=1000.0," + " m1_rate=3.0, m5_rate=4.0, m15_rate=5.0, mean_rate=2.0, rate_unit=events/second, duration_unit=milliseconds"); }