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 "Zakaria, Faheem" <fa...@fmr.com> on 2007/03/08 23:26:06 UTC

Using LogManager.getLogger(String)

Hello,

I am working on refactoring an existing application with a proprietary
logging framework.  We are integrating with Log4j and need to understand
performance/scalability as well as any best practices surrounding the
use of LogManager.getLogger(String).  Since this is a legacy system, our
plan is to lookup the Log4j Logger on every log request through
LogManager.getLogger(String).  So, the logging paradigm throughout the
entire application would be:

LogManager.getLogger("com.myclass").info("My log message 1");
...
LogManager.getLogger("com.myclass").info("My log message 2");
...
LogManager.getLogger("com.myclass").info("My log message 3");


Versus:


Final static Logger logger = Logger.getLogger("com.myclass");
...
logger.info("My log message 1");
logger.info("My log message 2");
logger.info("My log message 3");


1. Is it okay to use LogManager in this manner?
2. Are there any performance issues with this approach?
3. Are there any scalability concerns with this approach?
4. Will reloading the log4j.xml configuration work with this approach?
5. Instead of using the LogManager, does it make sense to use a static
ConcurrentHashMap to store ("logger name",Logger) key value pairs and
perform a local Logger lookup on every log request?
6. What would you recommend?

Any help would be appreciated.  Thank you.

Faheem Zakaria
Software Engineer






Re: Using LogManager.getLogger(String)

Posted by Curt Arnold <ca...@apache.org>.
On Mar 8, 2007, at 4:26 PM, Zakaria, Faheem wrote:

> Since this is a legacy system, our
> plan is to lookup the Log4j Logger on every log request through
> LogManager.getLogger(String).

Could you explain your reasoning here.  Maybe give some examples of  
the existing logging calls in your code and why you think you should  
repeatedly call getLogger.


>
>
> 1. Is it okay to use LogManager in this manner?

Yes, but not advisable.

> 2. Are there any performance issues with this approach?

Likely substantial.

> 3. Are there any scalability concerns with this approach?

Possibly.

> 4. Will reloading the log4j.xml configuration work with this approach?

Shouldn't introduce any new problems.

> 5. Instead of using the LogManager, does it make sense to use a static
> ConcurrentHashMap to store ("logger name",Logger) key value pairs and
> perform a local Logger lookup on every log request?

Duplicates what should be going on in LogManager, might be more  
efficient depending on the implementation of LogManager.

> 6. What would you recommend?





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