Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference doc update for logging #4593

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/netty.adoc[Netty]
** xref:reference/okhttpclient.adoc[OkHttpClient]
* xref:guides.adoc[Guides]
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