• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

selected pacakges logging

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

In a huge application comprising of numerous packages how do we selectively enable logging for a few packages & disable logging for those packages where logging is not required.
What parameter settings i need to make to my log4j.properties file to achieve the same.

It would be really helpful if someone provided an illustration for the same

Bye
Mahesh
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your post it is hard to tell what level of detail to use, but for general help, the log4j short manual should help. For much more detailed help, I highly recommend the The complete log4j Manual available in pdf ($).

log4j uses a root logger. So, you can configure that to log at or above a certain level. Then if you use the package hierarchy to set up your Loggers you can configure the level for whatever part of the package hierarchy you are interested in; e.g., setting up Loggers like like one of these that uses the class name is using the package hierarchy:


Configure the Root Logger level and appenders A1, A2:

log4j.rootLogger=WARN,A1,A2

Say you want a certail level of logging from org.apache classes in use:

log4j.logger.org.apache=INFO,A3
log4j.additivity.org.apache=false

Another level of logging from com.foo classes.
log4j.logger.com.foo=DEBUG,A1
log4j.additivity.com.foo=false

Not showing configuration of the three appenders mentioned, A1, A2, A3. You may want to log to the same or different log files. You can also set a Threshold on an appender.

Additivity can be turned on or off depending on your needs.

Need more help? Post your log4j.properties file (or reasonable sized snippet from it) and indicate what you've tried and what did or didn't work.
[ March 25, 2005: Message edited by: Carol Enderlin ]
 
Sheriff
Posts: 9103
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
posted April 20, 2005 01:29 AM

This sounds like what I'm
looking for, but I'm using a log4j.xml file. Does anyone know where I can find an example of this
sort of thing in an xml file rather than in a properties file?


Carol Enderlin

posted April 20, 2005 08:37 AM

The best source of examples (and explanations!) of the xml
files that I am aware of is Ceki G�lc�'s complete log4j manual (already gave the URL above). A
modified example from the manual's examples:

code:


<logger name="chapter3.Foo" additivity="false">
<level value="debug" />
<appender-ref ref="FOO" />
</logger>
<root>
<level value ="warn" />
<appender-ref ref="STDOUT" />
</root>


You can specify different levels for different loggers and/or different thresholds for different
appenders.

If your xml needs more help than that, please post a snippet so we can work off yours rather than
the examples.

 
Marilyn de Queiroz
Sheriff
Posts: 9103
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Carol. I'll try it out in the morning. (I'm really glad I copied your answer before the disk crashed).
reply
    Bookmark Topic Watch Topic
  • New Topic