[slf4j-user] logging array, strange behavior
Chris Pratt
thechrispratt at gmail.com
Thu Nov 10 20:07:33 CET 2011
Yes, remember that one of the overridden info methods is info (String msg,
String[] args). In your first test you used this version of the method,
which did exactly as you instructed and wrote out the first argument in the
array in the first replacement position. If you want it to treat the array
as a single argument try log.info("Just the array <{}>", (Object)array);
(*Chris*)
On Thu, Nov 10, 2011 at 10:59 AM, Colin Ingarfield <colini at alumni.utexas.net
> wrote:
> 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
> ______________________________**_________________
> slf4j-user mailing list
> slf4j-user at qos.ch
> http://mailman.qos.ch/mailman/**listinfo/slf4j-user<http://mailman.qos.ch/mailman/listinfo/slf4j-user>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-user/attachments/20111110/6246c169/attachment.html>
More information about the slf4j-user
mailing list