Spring Boot Logging JSON

Enables JSON logging in Spring Boot applications

License

License

Categories

Categories

Spring Boot Container Microservices JSON Data Logging Application Layer Libs
GroupId

GroupId

io.github.goetschalckx
ArtifactId

ArtifactId

spring-boot-logging-json
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Spring Boot Logging JSON
Enables JSON logging in Spring Boot applications
Project URL

Project URL

https://github.com/goetschalckx/spring-boot-logging-json
Source Code Management

Source Code Management

https://github.com/goetschalckx/spring-boot-logging-json

Download spring-boot-logging-json

Dependencies

runtime (2)

Group / Artifact Type Version
net.logstash.logback : logstash-logback-encoder jar 6.3
ch.qos.logback : logback-classic jar 1.2.0

Project Modules

There are no modules declared in this project.

Build Status License

Coverage Codacy Codacy Coverage CodeFactor Vulnerabilities

Release Snapshot

spring-boot-logging-json

by Eric Goetschalckx

json structured JSON log support for Spring Boot applications.

This capability works best in environments using log aggregation tools like Stackdriver or ELK.

When enabled, each log event emitted is a minified JSON object containing the log message and other metadata.

Unlocks more potential from the Logstash Logback JSON encoder.

Having metadata in discrete JSON fields allows for advanced queries and visualizations in log aggregation UIs.

Uses high-performance LMAX Async Disruptor console appender.

Simple Sample Log Statement

{
  "log" : "c.g.s.log.json.TestApplication",
  "lvl" : "INFO",
  "thread" : "main",
  "msg" : "log examples {logstash.argument=example}",
  "ts" : "2019-11-13T01:24:51.200+00:00",
  "HOSTNAME" : "dev",
  "logstash.argument" : "example",
  "logstash.marker" : {
    "json" : "example"
  },
  "tags" : [ "slf4j.marker" ],
  "mdc" : "example"
}

Top-level JSON fields can be added using:

Minimum Requirements

Requires

  • spring-boot v1.4.0.RELEASE+
  • logstash-logback-encoder v6.3+

Spring Profiles

Use the following Spring profile(s) to enable the various logging output options.

  • default or log-dev
    • "Standard" Spring logging, colorized, pretty-printed, etc...
    • No support for custom fields.
  • log-json
    • json structured logs to the console.
    • Supports custom JSON fields.
    • Intended for containerized deployments.

Profiles Drawback

The problem with this approach is that if you already use a custom Spring Profile besides default, you will get no logs, which is less than ideal.

Configuration

The following configuration properties are available for managing logging settings:

# Logging settings 
logging:
  
  # Newline-delimited JSON Logging Settings
  json:
      
    # Enable JSON pretty-print
    # Optional (default is false)
    pretty-print: false
io.github.goetschalckx

Goetschalckx

Versions

Version
0.1.1
0.1.0