Skip to content

Support logging formatted JSON messages by upgrading logback #2435

@james-johnston-thumbtack

Description

logback 1.5 includes the ability to log formatted JSON messages using the new withFormattedMessage XML option:
https://logback.qos.ch/manual/encoders.html

Example configuration snippet that outputs formatted JSON log messages using the new logback 1.5 functionality:

<!-- Adopted from https://github.com/tchiotludo/akhq/blob/0.26.0/src/main/resources/logback.xml -->
<configuration>
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <immediateFlush>true</immediateFlush>

        <encoder class="ch.qos.logback.classic.encoder.JsonEncoder">
            <withFormattedMessage>true</withFormattedMessage>
            <withMessage>false</withMessage>
            <withArguments>false</withArguments>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="stdout"/>
    </root>

    <logger name="org.apache" level="WARN" />
    <logger name="io.micronaut" level="WARN"/>
    <logger name="io.micronaut.context.DefaultApplicationContext" level="INFO" />
    <logger name="io.micronaut.runtime.Micronaut" level="INFO" />
</configuration>

PR #2350 would upgrade from logback 1.4, which was being implicitly chosen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions