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 Jordi <jb...@hotmail.com> on 2004/06/07 17:38:07 UTC

Different logging levels for each library client application

Hi,

I have a library with a small number of public methods, every method carrying a "client application id" parameter.

The number of different client ids can be between 3 and 10, no more.

I'd like to be able to set different logging levels for each client id.

My first guess was to set up parallel hierarchies like

- client1.com.wombat.clazz

- client2.com.wombat.clazz

so that I can set log4j.logger.client1=DEBUG and log4j.logger.client2=INFO

but I'm afraid that would impact performance negatively as I would have to call getLogger in each method call to retrieve the right logger for the request's client id.

Has anyone faced this problem before and found a better approach?

Rgds, *jordi

Re: Different logging levels for each library client application

Posted by Larry Young <ly...@dalmatian.com>.
Jordi,

         This is exactly what I'm doing right now, and it works great!

         My situation is a bit different.  In my case, I don't like the 
idea of log-levels, so I've replaced it with log-types, each of which is 
totally independent of the others.  In my code, I simply instantiate 
(statically) the logging types that I want to use and then use them as 
needed.  And in my config file, I simply define each one as you have 
"guessed" in your original email.

         Now in my case, I don't actually use the DEBUG vs INFO values, I 
only use OFF & ALL, but the structure is the same.  Oh, and another 
difference is that I choose the logger that I want to use directly in the 
code, whereas you would need to find it when the method is called.  Perhaps 
something as simple as an array, if the valid ids are really between 3 & 10 
as you say.  Or, if you meant that there will be 3 - 10 unknown ids, you'll 
probably need something like a hash to look them up efficiently each time 
your method is called.

         Good luck.

--- regards ---
Larry


At 08:38 AM 6/7/04, you wrote:
>Hi,
>
>I have a library with a small number of public methods, every method 
>carrying a "client application id" parameter.
>
>The number of different client ids can be between 3 and 10, no more.
>
>I'd like to be able to set different logging levels for each client id.
>
>My first guess was to set up parallel hierarchies like
>
>- client1.com.wombat.clazz
>
>- client2.com.wombat.clazz
>
>so that I can set log4j.logger.client1=DEBUG and log4j.logger.client2=INFO
>
>but I'm afraid that would impact performance negatively as I would have to 
>call getLogger in each method call to retrieve the right logger for the 
>request's client id.
>
>Has anyone faced this problem before and found a better approach?
>
>Rgds, *jordi

--------------------------
Larry Young
The Dalmatian Group
www.dalmatian.com 



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


Re: Different logging levels for each library client application

Posted by Ceki Gülcü <ce...@qos.ch>.
At 05:38 PM 6/7/2004, you wrote:
>Hi,
>
>I have a library with a small number of public methods, every method 
>carrying a "client application id" parameter.
>
>The number of different client ids can be between 3 and 10, no more.
>
>I'd like to be able to set different logging levels for each client id.
>
>My first guess was to set up parallel hierarchies like
>
>- client1.com.wombat.clazz
>
>- client2.com.wombat.clazz
>
>so that I can set log4j.logger.client1=DEBUG and log4j.logger.client2=INFO
>
>but I'm afraid that would impact performance negatively as I would have to 
>call getLogger in each method call to retrieve the right logger for the 
>request's client id.

No need to call getLogger() each time your methods are called. You can 
place the different loggers namely logger3, logger4, ..., logger10 in a 
HashMap (or even a Vector) and retrieve them from the HashMap. If a logger 
is not in the HashMap only then do you call getLogger().

>Has anyone faced this problem before and found a better approach?

The solution outlined above should work very well for the finite and 
delimited problem you describe.

>Rgds, *jordi

-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp  



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