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 dirk ooms <di...@onesparrow.com> on 2007/09/02 22:13:16 UTC

1.3 {} notation available in 1.2.x?

Hi,

i was using log4j 1.3, but  i am moving back to 1.2.15 now. i often used the 
{} symbols in my log statements, e.g. logger.info("blahblah {}", value);

1.2.x does not seem to understand this. is there any extension to 1.2.x that 
supports this notation?

cheers,
dirk

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


RE: 1.3 {} notation available in 1.2.x?

Posted by Scott Deboy <sd...@comotivsystems.com>.
Yes, in the extras library you'll find LogMF and LogSF.  You make static calls on LogMF or LogSF directly, passing in the logger.

I think we can integrate these methods into logger itself in an upcoming release.

Link to extras:
http://logging.apache.org/log4j/companions/extras/index.html

Link to extras javadoc:
See http://logging.apache.org/log4j/companions/extras/apidocs/index.html


Scott Deboy
COMOTIV SYSTEMS
111 SW Columbia Street Ste. 950
Portland, OR  97201

Telephone:      503.224.7496
Cell:           503.997.1367
Fax:            503.222.0185

sdeboy@comotivsystems.com

www.comotivsystems.com



-----Original Message-----
From: dirk ooms [mailto:dirk@onesparrow.com]
Sent: Sun 9/2/2007 1:13 PM
To: log4j-user@logging.apache.org
Subject: 1.3 {} notation available in 1.2.x?
 
Hi,

i was using log4j 1.3, but  i am moving back to 1.2.15 now. i often used the 
{} symbols in my log statements, e.g. logger.info("blahblah {}", value);

1.2.x does not seem to understand this. is there any extension to 1.2.x that 
supports this notation?

cheers,
dirk

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




Re: 1.3 {} notation available in 1.2.x?

Posted by Jacob Kjome <ho...@visi.com>.
On Tue, 4 Sep 2007 10:03:52 +0200
  dirk ooms <di...@onesparrow.com> wrote:
> Thanks guys for all the useful information. I opted for introducing the 
>slf4j 
> layer since:
> 1. it had the least impact on my existing 1.3 code: adapt import statements 
> and a replacement of Logger.getLogger() by LoggerFactory.getLogger()
> 2. it adds extra flexibility to switch to another logging framework 
> 
> Let me know if i am overlooking major disadvantages of this approach.

Using a repository selector is probably out of the question when using SLF4J 
unless you utilize a logging implementation that directly extends the SLF4J 
interfaces, such as Logback or Ceki's fork of Log4j.   Ask Ceki for the 
details.

Jake

> 
> thanks again,
> dirk
> 
> On Sunday 02 September 2007 22:13, dirk ooms wrote:
>> Hi,
>>
>> i was using log4j 1.3, but  i am moving back to 1.2.15 now. i often used
>> the {} symbols in my log statements, e.g. logger.info("blahblah {}",
>> value);
>>
>> 1.2.x does not seem to understand this. is there any extension to 1.2.x
>> that supports this notation?
>>
>> cheers,
>> dirk


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


Re: 1.3 {} notation available in 1.2.x?

Posted by dirk ooms <di...@onesparrow.com>.
Thanks guys for all the useful information. I opted for introducing the slf4j 
layer since:
1. it had the least impact on my existing 1.3 code: adapt import statements 
and a replacement of Logger.getLogger() by LoggerFactory.getLogger()
2. it adds extra flexibility to switch to another logging framework 

Let me know if i am overlooking major disadvantages of this approach.

thanks again,
dirk

On Sunday 02 September 2007 22:13, dirk ooms wrote:
> Hi,
>
> i was using log4j 1.3, but  i am moving back to 1.2.15 now. i often used
> the {} symbols in my log statements, e.g. logger.info("blahblah {}",
> value);
>
> 1.2.x does not seem to understand this. is there any extension to 1.2.x
> that supports this notation?
>
> cheers,
> dirk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org

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


Re: 1.3 {} notation available in 1.2.x?

Posted by Ceki Gulcu <li...@qos.ch>.
Hi Dirk,

Have you considered using the SLF4J API? It supports log4j 1.2 as well as other 
logging systems. Moreover, you would not need to change your code since SLF4J
supports parameterized syntax you are currently using.

HTH,

dirk ooms wrote:
> Hi,
> 
> i was using log4j 1.3, but  i am moving back to 1.2.15 now. i often used the 
> {} symbols in my log statements, e.g. logger.info("blahblah {}", value);
> 
> 1.2.x does not seem to understand this. is there any extension to 1.2.x that 
> supports this notation?
> 
> cheers,
> dirk


-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch

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


Re: 1.3 {} notation available in 1.2.x?

Posted by Curt Arnold <ca...@apache.org>.
On Sep 3, 2007, at 3:51 PM, Ceki Gulcu wrote:

>
> Curt Arnold wrote:
>> As Scott mentioned, the extras companion contains two utility  
>> classes to support parameterized logging, LogSF and LogMF.  LogSF  
>> uses the log4j 1.3 message patterns (curly braces, no argument  
>> count or qualifiers) and LogMF which uses the  
>> java.text.MessageFormat.  LogSF only justification is to support  
>> migration of existing log4j 1.3 code, if you were writing new  
>> statements, I would encourage you to use LogMF since  
>> java.text.MessageFormat's pattern syntax is part of the JDK, well  
>> documented and much richer.  As implemented  in LogMF and LogSF,  
>> there is no detectable performance difference between the two.
>
> In test I've done, LogSF aka SLF4J style curly braces perform much  
> better than
> java.text.MessageFormat, actually at least 10 times faster. Even  
> for *enabled*
> statements, taking into account the overall cost of a logging  
> statement (and
> actually writing to file or some other destination), the difference  
> remains
> significant. A SLF4J style logging will perform twice as fast for  
> enabled log
> statements and at least 10 times as fast for *disabled* log  
> statements.
>

LogMF does not use java.text.MessageFormat's implementation when  
presented with a trivial pattern like "hello, {0}" which bypasses the  
relatively expensive java.text.MessageFormat.format(String, Object)  
implementation (which appears to create an array and delegate to  
format(String, Object[]).  This was based on benchmark done and  
posted back in early 2006 (http://marc.info/?l=log4j- 
dev&m=113719664927002&w=2) with subsequent optimization described in  
http://marc.info/?l=log4j-dev&m=113753508714633&w=2.  I benchmarked  
the crude out of the code back when it was originally written based  
on your concerns and I doubt your comments reflect the current  
performance of LogMF.


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


Re: 1.3 {} notation available in 1.2.x?

Posted by Ceki Gulcu <li...@qos.ch>.
Curt Arnold wrote:
> As Scott mentioned, the extras companion contains two utility classes to 
> support parameterized logging, LogSF and LogMF.  LogSF uses the log4j 
> 1.3 message patterns (curly braces, no argument count or qualifiers) and 
> LogMF which uses the java.text.MessageFormat.  LogSF only justification 
> is to support migration of existing log4j 1.3 code, if you were writing 
> new statements, I would encourage you to use LogMF since 
> java.text.MessageFormat's pattern syntax is part of the JDK, well 
> documented and much richer.  As implemented  in LogMF and LogSF, there 
> is no detectable performance difference between the two.

In test I've done, LogSF aka SLF4J style curly braces perform much better than
java.text.MessageFormat, actually at least 10 times faster. Even for *enabled*
statements, taking into account the overall cost of a logging statement (and
actually writing to file or some other destination), the difference remains
significant. A SLF4J style logging will perform twice as fast for enabled log
statements and at least 10 times as fast for *disabled* log statements.

On the other hand, java.text.MessageFormat's pattern syntax is indeed richer.
However, I believe this extra power is only rarely used in log statements.

I would recommend that the SLF4J API is given serious consideration in future
log4j releases. If there is support for the idea, I could do the necessary work.

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch

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


Re: 1.3 {} notation available in 1.2.x?

Posted by Ceki Gulcu <li...@qos.ch>.

Scott Deboy wrote:
> What about the option of adding support for messageFormat in logger itself in a future release? 
> 
> (which release?)

I think it's a good idea.

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch

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


RE: 1.3 {} notation available in 1.2.x?

Posted by Scott Deboy <sd...@comotivsystems.com>.
What about the option of adding support for messageFormat in logger itself in a future release? 

(which release?)


Scott Deboy



-----Original Message-----
From: Curt Arnold [mailto:carnold@apache.org]
Sent: Sun 9/2/2007 10:38 PM
To: Log4J Users List
Subject: Re: 1.3 {} notation available in 1.2.x?
 

On Sep 2, 2007, at 3:13 PM, dirk ooms wrote:

> Hi,
>
> i was using log4j 1.3, but  i am moving back to 1.2.15 now. i often  
> used the
> {} symbols in my log statements, e.g. logger.info("blahblah {}",  
> value);
>
> 1.2.x does not seem to understand this. is there any extension to  
> 1.2.x that
> supports this notation?
>

As Scott mentioned, the extras companion contains two utility classes  
to support parameterized logging, LogSF and LogMF.  LogSF uses the  
log4j 1.3 message patterns (curly braces, no argument count or  
qualifiers) and LogMF which uses the java.text.MessageFormat.  LogSF  
only justification is to support migration of existing log4j 1.3  
code, if you were writing new statements, I would encourage you to  
use LogMF since java.text.MessageFormat's pattern syntax is part of  
the JDK, well documented and much richer.  As implemented  in LogMF  
and LogSF, there is no detectable performance difference between the  
two.

Basically, your:

logger.info("blahblah {}", value);

becomes

LogSF.info(logger, "blahblah {}", value);

A couple of regex search and replaces should be able to convert a  
code base pretty quickly.  If someone wants to donate a conversion  
script, please feel free.  A little perl script would likely work for  
most cases, or you could write up something with Eclipse's (or maybe  
NetBeans) refactoring capabilities.







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




Re: 1.3 {} notation available in 1.2.x?

Posted by Curt Arnold <ca...@apache.org>.
On Sep 2, 2007, at 3:13 PM, dirk ooms wrote:

> Hi,
>
> i was using log4j 1.3, but  i am moving back to 1.2.15 now. i often  
> used the
> {} symbols in my log statements, e.g. logger.info("blahblah {}",  
> value);
>
> 1.2.x does not seem to understand this. is there any extension to  
> 1.2.x that
> supports this notation?
>

As Scott mentioned, the extras companion contains two utility classes  
to support parameterized logging, LogSF and LogMF.  LogSF uses the  
log4j 1.3 message patterns (curly braces, no argument count or  
qualifiers) and LogMF which uses the java.text.MessageFormat.  LogSF  
only justification is to support migration of existing log4j 1.3  
code, if you were writing new statements, I would encourage you to  
use LogMF since java.text.MessageFormat's pattern syntax is part of  
the JDK, well documented and much richer.  As implemented  in LogMF  
and LogSF, there is no detectable performance difference between the  
two.

Basically, your:

logger.info("blahblah {}", value);

becomes

LogSF.info(logger, "blahblah {}", value);

A couple of regex search and replaces should be able to convert a  
code base pretty quickly.  If someone wants to donate a conversion  
script, please feel free.  A little perl script would likely work for  
most cases, or you could write up something with Eclipse's (or maybe  
NetBeans) refactoring capabilities.







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