logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <g.x.cusano.pin...@accenture.com>
Subject Avoiding the unnecessary message build cost
Date Mon, 04 Apr 2011 15:27:50 GMT
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<mailto: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.

Mime
View raw message