Miguel Ferreira
Miguel Ferreira

Reputation: 1417

Does micronaut framework support configuring logs as json?

I'm trying to configure a micronaut app to produce logs in json format. I found ways to configure the underlying logback to do that ([1]), but I'm wondering if it could also be done via Micronaut's configuration.

[1] - https://mathieularose.com/logback-json/

Upvotes: 1

Views: 1752

Answers (1)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27255

Does micronaut framework support configuring logs as json?

Yes.

See the project at https://github.com/jeffbrown/miguelferreirajsonlogback.

https://github.com/jeffbrown/miguelferreirajsonlogback/blob/f3e0e6074cfa5724ac4bce5da05e90d8435893a4/build.gradle#L27

runtimeOnly("ch.qos.logback.contrib:logback-json-classic:0.1.5")

https://github.com/jeffbrown/miguelferreirajsonlogback/blob/f3e0e6074cfa5724ac4bce5da05e90d8435893a4/src/main/resources/logback.xml

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
            <jsonFormatter
                    class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
                <prettyPrint>true</prettyPrint>
            </jsonFormatter>
            <timestampFormat>yyyy-MM-dd' 'HH:mm:ss.SSS</timestampFormat>
        </layout>
    </appender>


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

</configuration>

Upvotes: 1

Related Questions