Skip to content
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

Properties in a log statement are shoved in to message in JsonEncoder #837

Open
mityakoval opened this issue Jul 31, 2024 · 0 comments
Open

Comments

@mityakoval
Copy link

Hi!

I'm using a net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder and usually all the properties I add to my log statements are nicely displayed. One of the library's internal logs also seem to be in a JSON format but it's just getting formatted in to a string and shoved into the message property which is really hard to read.

{"app":"processor","time":"2024-07-31T15:12:31.301808321Z","logger":"com.azure.core.amqp.implementation.ReactorConnection","level":"INFO","thread":"reactor-executor-2","msg":"{\"az.sdk.message\":\"onConnectionShutdown. Shutting down.\",\"isTransient\":false,\"isInitiatedByClient\":false,\"shutdownMessage\":\"Finished processing pending tasks.\"}"}

Is there a way to instruct Logback to recognise the JSON logged by the library and merge according to the existing encoder config.

Here's the logback.xml:

<configuration>
    <contextName>processor</contextName>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <contextName>
                    <fieldName>app</fieldName>
                </contextName>
                <timestamp>
                    <fieldName>time</fieldName>
                    <timeZone>UTC</timeZone>
                </timestamp>
                <loggerName>
                    <fieldName>logger</fieldName>
                </loggerName>
                <logLevel>
                    <fieldName>level</fieldName>
                </logLevel>
                <threadName>
                    <fieldName>thread</fieldName>
                </threadName>
                <mdc/>
                <arguments>
                    <includeNonStructuredArguments>true</includeNonStructuredArguments>
                </arguments>
                <stackTrace>
                    <fieldName>stackTrace</fieldName>
                    <!-- maxLength - limit the length of the stack trace -->
                    <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                        <maxDepthPerThrowable>200</maxDepthPerThrowable>
                        <maxLength>14000</maxLength>
                        <rootCauseFirst>true</rootCauseFirst>
                    </throwableConverter>
                </stackTrace>
                <throwableClassName>
                    <fieldName>exceptionClass</fieldName>
                </throwableClassName>
                <message>
                    <fieldName>msg</fieldName>
                </message>
            </providers>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="STDOUT"/>
    </root>
    <logger name="org.eclipse.jetty" level="INFO"/>
    <logger name="io.netty" level="INFO"/>
    <logger name="io.ktor" level="INFO"/>
    <logger name="com.azure" level="INFO"/>
</configuration>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant