[slf4j-user] logging array, strange behavior

Colin Ingarfield colini at alumni.utexas.net
Thu Nov 10 19:59:52 CET 2011


Hello,

Today I noticed that slf4j/logback sometimes logs the entire contents of 
an array and sometimes just logs the first element.  Here is a test app:

public class LogbackTest {
     protected static final Logger log = 
LoggerFactory.getLogger(LogbackTest.class);

     public static final void main(String[] args) {
         String[] array = {"one", "two", "three"};

         log.info("Just the array <{}>", array);
         log.info("a var then the array {} <{}>", 10, array);
         log.info("the array <{}> then a var {}", array, 10);
     }
}

The output I get is:
12:54:19.366 [main] INFO  c.l.n.m.LogbackTest - Just the array <one>
12:54:19.372 [main] INFO  c.l.n.m.LogbackTest - a var then the array 10 
<[one, two, three]>
12:56:52.497 [main] INFO  c.l.n.m.LogbackTest - the array <[one, two, 
three]> then a var 10

When there is a single "{}" placeholder only the first element of the 
array is output.  When there are two placeholders all the elements are 
output.

This is slf4j 1.6.1 and logback classic/core 0.9.27.

Is this the expected behavior?

thanks,
Colin


More information about the slf4j-user mailing list