question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Logback Configuration XML] How to get StructuredArgument in Json Pattern

See original GitHub issue

I have following configuration:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
    <appender name="jsonConsoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <pattern>
                    <pattern>
                        {
                            "SESSION_ID": "%mdc{SESSION_UUID}"
                        }
                    </pattern>
                </pattern>
                <!-- log guid support -->
                <!-- StructuredArgument and Marker support -->
                <!--
                <arguments/>
                <logstashMarkers/>
                -->
                <stackTrace>
                    <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                        <maxDepthPerThrowable>10</maxDepthPerThrowable>
                        <maxLength>2048</maxLength>
                        <shortenedClassNameLength>32</shortenedClassNameLength>
                        <exclude>sun\.reflect\..*\.invoke.*</exclude>
                        <exclude>net\.sf\.cglib\.proxy\.MethodProxy\.invoke</exclude>
                        <rootCauseFirst>true</rootCauseFirst>
                    </throwableConverter>
                </stackTrace>
            </providers>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="jsonConsoleAppender" />
    </root>

</configuration>

I cannot figured out how to get value from structured argument property in JSON pattern. I added for example StructuredArgument log.info(“sample log”, kv(“SAMPLE_KEY”, “TEST”)); Thank you for help in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
philsttrcommented, Dec 3, 2019

Unfortunately, the pattern provider does not support structured arguments.

The arguments provider is the only provider that writes structured arguments.

Output field order is determined by the order in which the providers are added. Therefore, all of the structured arguments are going to be together. You could put pattern providers before and/or after them though.

0reactions
gmariotticommented, Jul 16, 2020

@philsttr Apologies in advance for resuming an old issue. Would it be possible to have a marker in the pattern, instead? What I would like to achieve is to have a custom Marker/StructuredArgument serialized as usual to JSON but wrote as a string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Logback Configuration XML] How to get StructuredArgument ...
I cannot figured out how to get value from structured argument property in JSON pattern. I added for example StructuredArgument log.info("sample ...
Read more >
Structured Logging with Structured Arguments - INNOQ
First, we enable JSON logging in Spring Boot. Then, we discuss how to write log statements to benefit from the structured log format....
Read more >
Structured logging with SLF4J and Logback - JRald Blog
In this article I will describe how to do structured logging in Java with usual logging libraries like SLF4J et Logback.
Read more >
Java: How to log raw JSON as JSON and avoid escaping ...
To solve this, try the following in your logback.xml: ... (2016) groovy logback config that dumps out your logs in json format to...
Read more >
How to Log in JSON with Logback - Mathieu Larose
The source code is available at https://github.com/larose/logback-json-example. End result: logger.debug("Hello world."); { "timestamp" : ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found