diff --git a/README.adoc b/README.adoc index b4100f602..80b9f038f 100644 --- a/README.adoc +++ b/README.adoc @@ -143,6 +143,101 @@ filter { } } +===== JSON Logback with Logstash + +Often you do not want to store your logs in a text file but in a JSON file that Logstash can immediately pick. To do that you have to do the following (for readability +we're passing the dependencies in the `groupId:artifactId:version` notation. + +*Dependencies setup* + +- Ensure that Logback is on the classpath (`ch.qos.logback:logback-core`) +- Add Logstash Logback encode - example for version `4.6` : `net.logstash.logback:logstash-logback-encoder:4.6` + +*Logback setup* + +Below you can find an example of a Logback configuration (file named `https://github.com/spring-cloud-samples/sleuth-documentation-apps/blob/master/service1/src/main/resources/logback-spring.xml[logback-spring.xml]`) that: + +- logs information from the application in a JSON format to a `build/${spring.application.name}.json` file +- has commented out two additional appenders - console and standard log file +- has the same logging pattern as the one presented in the previous section + +[source,xml] +----- + + + + ​ + + + ​ + + + + + + + + INFO + + + ${CONSOLE_LOG_PATTERN} + utf8 + + + + ​ + + ${LOG_FILE} + + ${LOG_FILE}.%d{yyyy-MM-dd}.gz + 7 + + + ${CONSOLE_LOG_PATTERN} + utf8 + + + ​ + + + ${LOG_FILE}.json + + ${LOG_FILE}.json.%d{yyyy-MM-dd}.gz + 7 + + + + + UTC + + + + { + "severity": "%level", + "service": "${springAppName:-}", + "trace": "%X{X-B3-TraceId:-}", + "span": "%X{X-B3-SpanId:-}", + "exportable": "%X{X-Span-Export:-}", + "pid": "${PID:-}", + "thread": "%thread", + "class": "%logger{40}", + "rest": "%message" + } + + + + + + ​ + + + + + + +----- + === Adding to the project ==== Only Sleuth (log correlation) diff --git a/docs/src/main/asciidoc/intro.adoc b/docs/src/main/asciidoc/intro.adoc index 7124f2af3..c4d7f6217 100644 --- a/docs/src/main/asciidoc/intro.adoc +++ b/docs/src/main/asciidoc/intro.adoc @@ -135,6 +135,29 @@ filter { } } +===== JSON Logback with Logstash + +Often you do not want to store your logs in a text file but in a JSON file that Logstash can immediately pick. To do that you have to do the following (for readability +we're passing the dependencies in the `groupId:artifactId:version` notation. + +*Dependencies setup* + +- Ensure that Logback is on the classpath (`ch.qos.logback:logback-core`) +- Add Logstash Logback encode - example for version `4.6` : `net.logstash.logback:logstash-logback-encoder:4.6` + +*Logback setup* + +Below you can find an example of a Logback configuration (file named `https://github.com/spring-cloud-samples/sleuth-documentation-apps/blob/master/service1/src/main/resources/logback-spring.xml[logback-spring.xml]`) that: + +- logs information from the application in a JSON format to a `build/${spring.application.name}.json` file +- has commented out two additional appenders - console and standard log file +- has the same logging pattern as the one presented in the previous section + +[source,xml] +----- +include::https://raw.githubusercontent.com/spring-cloud-samples/sleuth-documentation-apps/master/service1/src/main/resources/logback-spring.xml[] +----- + === Adding to the project ==== Only Sleuth (log correlation)