This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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: 9099
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: 9099
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).
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!