You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Ashish Kulkarni <as...@gmail.com> on 2008/08/04 21:45:03 UTC

Logging messages using java 1.5 format string

Hi
Is there anyway to format the log messages using java 1.5 format
capabilities
for example i can have a nice formatted out put using
System.out.format("Number of Users on Registry %1$s, is %2$d",
registry.getName(), userSet.size());

Can i do some thing like
logger.debug("Number of Users on Registry %1$s, is %2$d",
registry.getName(), userSet.size());

I would hate to have to do
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb);
formatter.format("Number of Users on Registry %1$s, is %2$d",
registry.getName(), userSet.size());
logger.debug(sb);

to get formatted output,
Any ideas

Ashish

Re: Logging messages using java 1.5 format string

Posted by Jacob Kjome <ho...@visi.com>.
Thorbjørn Ravn Andersen wrote:
> Ashish Kulkarni skrev  den 04-08-2008 21:45:
>> Hi
>> Is there anyway to format the log messages using java 1.5 format
>> capabilities
>> for example i can have a nice formatted out put using
>> System.out.format("Number of Users on Registry %1$s, is %2$d",
>> registry.getName(), userSet.size());
>>   
> Use slf4j as the logging interface and use log4j as the backend.
> 
> You can then call
> 
> log.debug("Name: {} Size {}", "Foo", new Integer(10));
> 
> 

No need for SLF4J.  Use the Log4j "extras" companion [1] LogMF [2] or LogSF [3]
utility classes.

[1] http://logging.apache.org/log4j/companions/extras/download.html
[2]
http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/LogMF.html
[3]
http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/LogSF.html

Jake

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Logging messages using java 1.5 format string

Posted by Thorbjørn Ravn Andersen <th...@gmail.com>.
Ashish Kulkarni skrev  den 04-08-2008 21:45:
> Hi
> Is there anyway to format the log messages using java 1.5 format
> capabilities
> for example i can have a nice formatted out put using
> System.out.format("Number of Users on Registry %1$s, is %2$d",
> registry.getName(), userSet.size());
>   
Use slf4j as the logging interface and use log4j as the backend.

You can then call

log.debug("Name: {} Size {}", "Foo", new Integer(10));


-- 
  Thorbjørn Ravn Andersen          "... plus... Tubular Bells!"


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org