[slf4j-user] Avoiding new line after log messages

simon skitching at apache.org
Fri Jan 4 20:04:25 CET 2008


On Fri, 2008-01-04 at 12:16 -0600, Jacob Kjome wrote:
> On Fri, 04 Jan 2008 18:54:06 +0100
>   simon <skitching at apache.org> wrote:
> > 
> > On Fri, 2008-01-04 at 11:32 +0100, Guy Pardon wrote:
> >> Is there a way to log multiple strings in different calls to the
SLF4J  
> >> API, without a newline in between?
> > 
> > No.
> > 
> 
> What do you mean "No"?  That's up to the logging implementation
configuration, 
> isn't it?  SLF4J, unless it is just the simple one that does
System.out, has 
> nothing specifically to say about newlines.
> 
> That said, the layout assigned to an appender would need to not define
the 
> newline.  That would mean that the developer would need to include a
newline 
> as needed when performing logging statements.

Well, either 
(a) SLF4J buffers/merges messages and only passes them through to the
underlying system once a message is complete, or 
(b) SLF4J passes them through immediately, but the underlying logging
lib merges them, or
(c) SLF4J passes them through immediately and an appender of the
underlying logging lib merges them.

Option (a) is theoretically possible, but I can definitely say that no
such feature currently exists. And I think it would be a bad idea. If
code logs several "parts" then fails to do the "flush" then the whole
message gets lost. Plus it adds complexity to the "logging adapter"
layer that almost nobody will use.

Option (b) and (c) are not feasable because how an app logs is
determined by the app programmer but what logging lib/adapters are
configured are determined by the app deployer. There is no cross-library
convention for merging messages, so the application doing the logging
will never know whether the lib/adapters available at runtime are
capable of merging messages or not.

And furthermore, I can say that I am not aware of any such "message
merging" functionality in log4j or the java.util.logging implementation.

So I think "no" was a pretty fair answer.

If someone wants to merge several strings into a message, then they
should use a StringBuffer, and then log its contents once everything
necessary has been collected. As one atomic log call.

Regards,

Simon





More information about the slf4j-user mailing list