Skip to content

Commit

Permalink
Reference doc update for logging (#4593)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Jan 19, 2024
1 parent d959d9b commit 7f0d479
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
** xref:reference/httpcomponents.adoc[HttpComponents Client]
** xref:reference/jetty.adoc[Jetty and Jersey]
** xref:reference/jvm.adoc[JVM]
** xref:reference/logging.adoc[Logging]
** xref:reference/mongodb.adoc[MongoDB]
** xref:reference/netty.adoc[Netty]
** xref:reference/okhttpclient.adoc[OkHttpClient]
Expand Down
31 changes: 31 additions & 0 deletions docs/modules/ROOT/pages/reference/logging.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[[overview]]
= Logging Metrics Instrumentation

Micrometer can add metrics to different loggers

* <<logging-log4j, Log4j>>
* <<logging-logback, Logback>>

[[logging-log4j]]
== Log4j Instrumentation

[source,java,subs=+attributes]
-----
// Setting up instrumentation
include::{include-core-test-java}/io/micrometer/core/instrument/binder/logging/Log4j2MetricsTest.java[tags=setup, indent=0]
// Usage example
include::{include-core-test-java}/io/micrometer/core/instrument/binder/logging/Log4j2MetricsTest.java[tags=example, indent=0]
-----

[[logging-logback]]
== Logback Instrumentation

[source,java,subs=+attributes]
-----
// Setting up instrumentation
include::{include-core-test-java}/io/micrometer/core/instrument/binder/logging/LogbackMetricsTest.java[tags=setup, indent=0]
// Usage example
include::{include-core-test-java}/io/micrometer/core/instrument/binder/logging/LogbackMetricsTest.java[tags=example, indent=0]
-----
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ static void cleanUpAfterAll() {

@Test
void log4j2LevelMetrics() {
// tag::setup[]
new Log4j2Metrics().bindTo(registry);
// end::setup[]

assertThat(registry.get("log4j2.events").counter().count()).isEqualTo(0.0);

// tag::example[]
Logger logger = LogManager.getLogger(Log4j2MetricsTest.class);
Configurator.setLevel(Log4j2MetricsTest.class.getName(), Level.INFO);
logger.info("info");
Expand All @@ -80,6 +83,7 @@ void log4j2LevelMetrics() {
assertThat(registry.get("log4j2.events").tags("level", "error").counter().count()).isEqualTo(1.0);
assertThat(registry.get("log4j2.events").tags("level", "debug").counter().count()).isEqualTo(0.0);
assertThat(registry.get("log4j2.events").tags("level", "trace").counter().count()).isEqualTo(0.0);
// end::example[]
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class LogbackMetricsTest {

@BeforeEach
void bindLogbackMetrics() {
// tag::setup[]
logbackMetrics = new LogbackMetrics();
logbackMetrics.bindTo(registry);
// end::setup[]
}

@AfterEach
Expand All @@ -62,6 +64,7 @@ void closeLogbackMetrics() {
void logbackLevelMetrics() {
assertThat(registry.get("logback.events").counter().count()).isEqualTo(0.0);

// tag::example[]
logger.setLevel(Level.INFO);

logger.warn("warn");
Expand All @@ -70,6 +73,7 @@ void logbackLevelMetrics() {

assertThat(registry.get("logback.events").tags("level", "warn").counter().count()).isEqualTo(1.0);
assertThat(registry.get("logback.events").tags("level", "debug").counter().count()).isEqualTo(0.0);
// end::example[]
}

@Issue("#183")
Expand Down

0 comments on commit 7f0d479

Please sign in to comment.