logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Avoiding the unnecessary message build cost
Date Wed, 06 Apr 2011 05:16:39 GMT
See the LogMF or LogSF classes.  LogMF used MessageFormat type format specifiers ("{1}") while
LogSF uses SLF4J format specifiers ("{}") .

varargs were introduced in Java 5 and have an unavoidable array construction/destruction expense
even if the level is not reached.  The LogMF and LogSF classes approximate the usability of
varargs by having a lot of different signatures.




On Apr 4, 2011, at 10:27 AM, <g.x.cusano.pineda@accenture.com> <g.x.cusano.pineda@accenture.com>
wrote:

> Hi,
>       why don't we add a method in the Logger class or at least a Util with a method
like the following one in order to avoid the cost of the message build.
>       In this way we'll not have to build the message unless the priority is enabled
for the logger.
>  
>       I'll wait for your thoughts.
>  
> Regards,
>  
> import org.apache.log4j.Logger;
> import org.apache.log4j.Priority;
>  
> public class LoggerUtil {
>  
>     static public void log(Logger logger, Priority priority, Object... objs){
>  
>         if (logger.isEnabledFor(priority) ){
>             StringBuffer sb = new StringBuffer();
>             for(Object obj : objs){
>                 sb.append( obj.toString() );
>             }
>             logger.log(priority, sb.toString() );
>         }
>     }
> }
>  
>  
> Cusano Pineda, Gerardo H.
> Information System Engineer
> Accenture – System Integration & Technology
> Buenos Aires, Argentina
> * g.x.cusano.pineda@accenture.com
> 
> This message is for the designated recipient only and may contain privileged, proprietary,
or otherwise private information. If you have received it in error, please notify the sender
immediately and delete the original. Any other use of the email by you is prohibited.


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


Mime
View raw message