[logback-user] How to change the log level label with slf4j?

Frédérick Sauvage Rueangpanichpiban frederick.sauvage at gmail.com
Thu Jun 2 15:41:07 CEST 2022


Hi all

I'm trying to change the label in the log. I only want to get
{"level":"WARNING","msg":"test"} instead of {"level":"WARN","msg":"test"}.

My class is:

package com.abc.def;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;import
org.springframework.boot.SpringApplication;import
org.springframework.boot.autoconfigure.SpringBootApplication;import
org.springframework.boot.builder.SpringApplicationBuilder;import
org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplicationpublic class Application extends
SpringBootServletInitializer {

    private static final Logger LOG =
LoggerFactory.getLogger(Application.class);

    @Override
    protected SpringApplicationBuilder
configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);

    }

    public static void main(String[] args) {
        LOG.warn("test");
        SpringApplication.run(Application.class, args);
    }

}

My logback.xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <property resource="application.properties" />
   <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
      <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
         <providers>
            <logLevel>
               <fieldName>level</fieldName>
            </logLevel>
            <arguments>
               <includeNonStructuredArguments>false</includeNonStructuredArguments>
            </arguments>
            <stackTrace>
               <fieldName>stack</fieldName>
            </stackTrace>
            <message>
               <fieldName>msg</fieldName>
            </message>
         </providers>
      </encoder>
   </appender>
   <root level="INFO">
      <appender-ref ref="CONSOLE" />
   </root>
</configuration>

I tried many changes but finally I don't any solution except creating a new
class that extends
net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder.

That seems a big stuff for a very small change.


I posted already in stackoverflow
https://stackoverflow.com/questions/72476767/how-to-change-the-log-level-label-with-slf4j


Thanks for helps
-------------- section suivante --------------
Une pièce jointe HTML a été nettoyée...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20220602/31fbbc6a/attachment.html>


More information about the logback-user mailing list