InstrumentedAppender extends UnsynchronizedAppenderBase<ILoggingEvent> { @Override public void start() { this.all = registry.meter(name(getName(), "all")); this.trace = registry.meter(name(getName(), "trace")); this.debug = registry.meter(name(getName(), "debug")); this.info = registry.meter(name(getName(), "info")); this.warn = registry.meter(name(getName(), "warn")); this.error = registry.meter(name(getName(), "error")); super.start(); } InstrumentedAppender();  InstrumentedAppender(String registryName);  InstrumentedAppender(MetricRegistry registry); @Override void start(); static final String DEFAULT_REGISTRY; static final String REGISTRY_PROPERTY_NAME; }
@Test public void usesSharedRegistries() { String registryName = "registry"; SharedMetricRegistries.add(registryName, registry); final InstrumentedAppender shared = new InstrumentedAppender(registryName); shared.start(); when(event.getLevel()).thenReturn(Level.INFO); shared.doAppend(event); assertThat(registry.meter(METRIC_NAME_PREFIX + ".info").getCount()) .isEqualTo(1); }
@Test public void usesDefaultRegistry() { SharedMetricRegistries.add(InstrumentedAppender.DEFAULT_REGISTRY, registry); final InstrumentedAppender shared = new InstrumentedAppender(); shared.start(); when(event.getLevel()).thenReturn(Level.INFO); shared.doAppend(event); assertThat(SharedMetricRegistries.names()).contains(InstrumentedAppender.DEFAULT_REGISTRY); assertThat(registry.meter(METRIC_NAME_PREFIX + ".info").getCount()) .isEqualTo(1); }
@Test public void usesRegistryFromProperty() { SharedMetricRegistries.add("something_else", registry); System.setProperty(InstrumentedAppender.REGISTRY_PROPERTY_NAME, "something_else"); final InstrumentedAppender shared = new InstrumentedAppender(); shared.start(); when(event.getLevel()).thenReturn(Level.INFO); shared.doAppend(event); assertThat(SharedMetricRegistries.names()).contains("something_else"); assertThat(registry.meter(METRIC_NAME_PREFIX + ".info").getCount()) .isEqualTo(1); }