From 004b8aa9e10a1b9976ac168a56878295a95459fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Skj=C3=B8lberg?= Date: Mon, 20 Jan 2025 14:58:51 +0100 Subject: [PATCH] Improve docs (#70) --- guides/gRPC.md | 42 ++++++++++++++++++++++++++++++++---------- guides/web.md | 22 +++++++++++++++------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/guides/gRPC.md b/guides/gRPC.md index 8c086cd..4dc9682 100644 --- a/guides/gRPC.md +++ b/guides/gRPC.md @@ -215,25 +215,47 @@ Add the `GrpcLoggingScopeContextInterceptor` interceptor to your gRPC services. ## Running applications locally For 'classic' one-line log output when running a server locally, additionally add the logging test artifacts to the main scope during local execution only. - * Maven: Use profiles - * Gradle: - * Use configurations, and/or - * add dependencies directly to task +* Maven: Use profiles +* Gradle: + * Use configurations, and/or + * add dependencies directly to task
Gradle bootRun example ```groovy -bootRun { - dependencies { - implementation("no.entur.logging.cloud:spring-boot-starter-gcp-web-test") - implementation("no.entur.logging.cloud:request-response-spring-boot-starter-gcp-web-test") - } +dependencies { + // Setup HumanReadableJsonApplicationListener without reflection + compileOnly("no.entur.logging.cloud:test-logback") { transitive = false } } -``` +tasks.register("logPlainly") { + dependencies { + implementation("no.entur.logging.cloud:request-response-spring-boot-starter-gcp-grpc-ecosystem-test") + implementation("no.entur.logging.cloud:spring-boot-starter-gcp-grpc-ecosystem-test") + } +} + +tasks.withType(JavaExec).configureEach { + dependsOn("logPlainly") +} +```
+Add an event listener to set your preferred log output: + +``` +@Component +@ConditionalOnClass(name = {"no.entur.logging.cloud.logback.logstash.test.CompositeConsoleOutputControl"}) +public class HumanReadableJsonApplicationListener implements ApplicationListener { + + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + CompositeConsoleOutputControl.useHumanReadableJsonEncoder(); + } +} +``` + ## Opting out Some included features can be removed by excluding the corresponding artifacts: diff --git a/guides/web.md b/guides/web.md index 2586f58..df9f722 100644 --- a/guides/web.md +++ b/guides/web.md @@ -267,22 +267,30 @@ For 'classic' one-line log output when running a server locally, additionally ad Gradle bootRun example ```groovy -bootRun { - dependencies { - implementation("no.entur.logging.cloud:spring-boot-starter-gcp-web-test") - implementation("no.entur.logging.cloud:request-response-spring-boot-starter-gcp-web-test") - } +dependencies { + // Setup HumanReadableJsonApplicationListener without reflection + compileOnly("no.entur.logging.cloud:test-logback") { transitive = false } +} + +tasks.register("logPlainly") { + dependencies { + implementation("no.entur.logging.cloud:request-response-spring-boot-starter-gcp-web-test") + implementation("no.entur.logging.cloud:spring-boot-starter-gcp-web-test") + } +} + +tasks.withType(JavaExec).configureEach { + dependsOn("logPlainly") } ``` -## Toggle output mode using profiles Add an event listener to set your preferred log output: ``` @Component -@Profile("local") +@ConditionalOnClass(name = {"no.entur.logging.cloud.logback.logstash.test.CompositeConsoleOutputControl"}) public class HumanReadableJsonApplicationListener implements ApplicationListener { @Override