javaspring-bootgoogle-maps-markerslogback

Tagging/log segregation | Need output of a value from a Logback marker without angular brackets?


In the below log statement, log_type is a marker but can the value be formatted to print it without the bracket since all markers have a single category as it is being used for segregation/categorisation on a HL.

ACTUAL: "log_type":["APPLICATION"]

EXPECTED: "log_type": "APPLICATION"

{"@timestamp":"2024-07-31T10:28:43.206598+05:30","@version":"1","message":"[SolJMS] Success - Connection established...","logger_name":"xx.xx.xx.SolJMSConnectionFactory","thread_name":"main","level":"INFO","level_value":20000,"serviceName":"xxx-xxx-xxxxx","log_type":["APPLICATION"]}

Solution

  • This was possible by using LoggingEventCompositeJsonEncoder and explicitly adding a custom field in the pattern which points to the raw marker.

    Note: This is only applicable only if there is a single element in the list.

        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <pattern>
                    <pattern>{"ltype": "%marker"}</pattern>
                </pattern>
            </providers>
        </encoder>