tersesystems / terse-logback

Structured Logging, Tracing, and Observability with Logback
https://tersesystems.github.io/terse-logback/
Other
196 stars 14 forks source link

Structured logging vs console output #138

Open skjolber opened 2 years ago

skjolber commented 2 years ago

Is your feature request related to a problem? Please describe. We have been using structured logging directly to console for quite some time for our kubernetes JVMs. However it seems the current implementation of this library only supports JSON to file.

Describe the solution you'd like Support JSON output to console as well, for deployed (production) workloads. For local development, we like plain old one-line logging. Unit testing against resulting JSON output should still work in development.

Describe alternatives you've considered None

Additional context Our agent requires "one linebreak per log statement".

wsargent commented 2 years ago

The logback-structured-config module is a packaging of logstash-logback-encoder that writes to a file amongst other things, but it's possible to set up the encoder to write to CONSOLE in exactly the same way.

The documentation at https://tersesystems.github.io/terse-logback/1.0.0/guide/structured-config/ explains how to set up appenders and multiple encoders

https://github.com/tersesystems/terse-logback/blob/master/logback-structured-config/src/main/resources/terse-logback/appenders/jsonfile-appenders.xml

And there's also https://github.com/tersesystems/terse-logback-showcase which shows some more options.