[Bug 184] New: Log array contents if only one parameter is specified in log string

http://bugzilla.slf4j.org/show_bug.cgi?id=184 Summary: Log array contents if only one parameter is specified in log string Product: SLF4J Version: unspecified Platform: PC OS/Version: All Status: NEW Severity: enhancement Priority: P3 Component: Core API AssignedTo: slf4j-dev@qos.ch ReportedBy: dumitru.postoronca@gmail.com Hello, When using Java5 var-args which are represented as an array, slf4j logs only the first item in the array (which is correct as per documentation, just that it's not very intuitive). Example: void getFilteredData(String... filterValues) { log.debug("Getting data, filtering using the following settings: {}", filterValues); return dao.doSomething(); } What happens is that only the first item is logged, insted of all the items being logged. The current work-around for this is to have the following method call: log.debug(".... {} {}", "", myArray); // note the first empty log parameter I would suggest enhancing the framework to automatically log the array content if only ONE {} parameter is specified in the log string. In this case: log.debug("... {}", myArray); // logs full array content, not only first item log.debug("... {}={}"); // logs as per current algorithm - first two items I believe it is safe to assume that people will use the log.debug(array) method only when they have more than two parameters to show, thus - if only one parameter is used, it's only reasonable that the FULL content of the passed object is logged, no matter the type. Thanks, Dima -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=184 Martin Ždila <m.zdila@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |m.zdila@gmail.com --- Comment #1 from Martin Ždila <m.zdila@gmail.com> 2010-07-16 15:30:11 --- I am giving a small vote for this bug, but there is better "workaround": log.debug(".... {}", new Object[] { myArray }); This "workaround" will also work for multiple substitutions: log.debug(".... {} {} {}", new Object[] { "something", myArray, 4 }); -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.

http://bugzilla.slf4j.org/show_bug.cgi?id=184 Joern Huxhorn <joern@huxhorn.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |joern@huxhorn.de --- Comment #2 from Joern Huxhorn <joern@huxhorn.de> 2010-07-16 18:16:35 --- There was a similar bug report for Logback: http://jira.qos.ch/browse/LBGENERAL-36 The solution involves counting of placeholders before transforming the Object[] into String[], i.e. handling an Object[] as argument similar to Object[0][] for a message with only one placeholder. See http://github.com/huxi/lilith/blob/master/lilith-data/logging/src/main/java/... This should really be fixed if we ever add varargs support to SLF4J... -- Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@pixie.qos.ch