Wednesday, August 10, 2022

SLF4J caveat on formatting

this will simply log NOTHING: in log.info(), the first parameter if it's a String it should be a formatting string, like "{}" .... if there is no format, nothing is logged.
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;


public class TestClass {
    public static void main(String[] args) {
        TestClass testClass = new TestClass();
        testClass.test();
    }

    public void test() {
        System.out.println(this.getClass().toString());
        Logger log = LoggerFactory.getLogger(this.getClass());
        List<String> responses = Arrays.asList("pippo", "pluto");
        log.info("", responses);

    }
}


1 comment:

vernetto said...

Trendoffice SK9248 Pro