-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Support structured logging as alternative to pattern layout logging #5479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This would be a nice addition. I had to customize https://github.com/logstash/logstash-logback-encoder project to integrate with Logentries which is also supporting JSON logs. Please note that logstash-logback-encoder is general-purpose JSON logging mechanism project. |
@mp911de Is there anything that's currently preventing JSON logging from working for you? I'm not sure that we really want to take on too much more responsibility in this area. We already have quite a maintenance burden trying to support three different logging systems. |
There's nothing which prevents JSON logging/log forwarding. It's more about the barrier to configure logging and set up conditional JSON logging. Usually, in dev, one does not want to have JSON logs but would enable JSON logging in staging/production. Using different logging config files and specifying I fully understand the maintenance efforts from your side. I'm considering maybe another approach with building/providing a starter in my own repo as I did JSON logging earlier. This way an extension existed one could use, and you don't have the maintenance hassle. |
That would certainly be better from our point of view. We could always add other extension points if needed. |
I'll follow that path then, thanks for your feedback. |
@mp911de have you gotten to implement the spring boot starter you mentioned? |
@imjorge I haven't been doing much on that end. |
Hi @cemo Here is an extract of my logback conf:
But I always get this error: Thanks |
Imho it is quite a common practice to have logs in json format, so it can be easily digested by logstash, graylog, splunk, etc. I think would be nice If spring boot would provide a simple option to switch the log format to json (and disable the banner at the same time). LogbackYou currently need to add the Log4j2you need to add jackson as dependency. And replace the entire configuration using an appender using the |
Log4j 2.14.0 will include a new component, JsonTemplateLayout that uses a template to describe the format of the JSON. It was donated by the author of https://github.com/vy/log4j2-logstash-layout who is now a committer on the Log4j project. As I recall the implementation does not require Jackson, although I would be surprised if Jackson is an issue for anyone using Spring Boot. |
We have had requests for integration with log tooling in Azure for JSON pattern layout. Is this going to be making it into an upcoming release? |
@csterwa ahead of that it's possible to do it ie via https://www.jvt.me/posts/2021/05/31/spring-boot-structured-logging/ |
@csterwa No imminent plans I'm afraid. Boot 3 / Framework 6 work will be taking priority. |
@philwebb Activating a profile would bring this a long way in order to be able to do something like: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator" />
<springProfile name="kubernetes">
<appender name="jsonAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
</springProfile>
<springProfile name="!kubernetes">
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
</springProfile>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration> I am aware that spring-cloud-kubernetes can define the profile, but I want to avoid pulling all of that in. WDYT? |
See #39814 for an example of a subtle bug that can occur with certain json logging configurations. |
Re-opening to address the test failures on Windows and to remind us to add something to the release notes. |
Spring Boot offers logging using a pattern for various log frameworks. In scenarios, where more context details would be useful, users need to adopt the pattern. Each value from the MDC needs to be configured independently which is a consistent source of work. It would be great to opt-in for a JSON log format that is used instead of the pattern layout to have a flexible field schema for later processing within log aggregators such as Splunk, Graylog, or Logstash.
Use-cases
See https://github.com/mp911de/logstash-gelf for examples.
The text was updated successfully, but these errors were encountered: