Skip to content

Commit c835af8

Browse files
committed
Add GELF to logging.adoc
1 parent e38e418 commit c835af8

File tree

1 file changed

+48
-0
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features

1 file changed

+48
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/logging.adoc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ Structured logging is a technique where the log output is written in a well-defi
443443
Spring Boot supports structured logging and has support for the following JSON formats out of the box:
444444

445445
* xref:#features.logging.structured.ecs[Elastic Common Schema (ECS)]
446+
* xref:#features.logging.structured.gelf[Graylog Extended Log Format (GELF)]
446447
* xref:#features.logging.structured.logstash[Logstash]
447448

448449
To enable structured logging, set the property configprop:logging.structured.format.console[] (for console output) or configprop:logging.structured.format.file[] (for file output) to the id of the format you want to use.
@@ -490,6 +491,53 @@ logging:
490491

491492
NOTE: configprop:logging.structured.ecs.service.name[] will default to configprop:spring.application.name[] if not specified.
492493

494+
NOTE: configprop:logging.structured.ecs.service.version[] will default to configprop:spring.application.version[] if not specified.
495+
496+
497+
498+
[[features.logging.structured.gelf]]
499+
=== Graylog Extended Log Format (GELF)
500+
https://go2docs.graylog.org/current/getting_in_log_data/gelf.html[Graylog Extended Log Format] is a JSON based logging format for the Graylog log analytics platform.
501+
502+
To enable the Graylog Extended Log Format, set the appropriate `format` property to `gelf`:
503+
504+
[configprops,yaml]
505+
----
506+
logging:
507+
structured:
508+
format:
509+
console: gelf
510+
file: gelf
511+
----
512+
513+
A log line looks like this:
514+
515+
[source,json]
516+
----
517+
{"version":"1.1","short_message":"Hello structured logging!","timestamp":1.725530750186E9,"level":6,"_level_name":"INFO","_process_pid":9086,"_process_thread_name":"main","host":"spring-boot-gelf","_log_logger":"com.slissner.springbootgelf.ExampleLogger","_userId":"1","_testkey_testmessage":"test"}
518+
----
519+
520+
This format also adds every key value pair contained in the MDC to the JSON object.
521+
You can also use the https://www.slf4j.org/manual.html#fluent[SLF4J fluent logging API] to add key value pairs to the logged JSON object with the https://www.slf4j.org/apidocs/org/slf4j/spi/LoggingEventBuilder.html#addKeyValue(java.lang.String,java.lang.Object)[addKeyValue] method.
522+
523+
The `service` values can be customized using `logging.structured.gelf.service` properties:
524+
525+
[configprops,yaml]
526+
----
527+
logging:
528+
structured:
529+
gelf:
530+
service:
531+
name: MyService
532+
version: 1.0
533+
environment: Production
534+
node-name: Primary
535+
----
536+
537+
NOTE: configprop:logging.structured.gelf.service.name[] will default to configprop:spring.application.name[] if not specified.
538+
539+
NOTE: configprop:logging.structured.gelf.service.version[] will default to configprop:spring.application.version[] if not specified.
540+
493541

494542

495543
[[features.logging.structured.logstash]]

0 commit comments

Comments
 (0)