• 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
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Log4j multiple log files

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 logging files. I have defined two appenders for the 2 files. In a class, if i need to output few logs to one file, and few to the other, do i need to have 2 logger instances. Is there a cleaner way of achieving this requirement? Or is there some log4j configuration that will help me?
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not really provide a lot of information about what is different about the log messages that they would be directed to different log files.

It would certainly work to create two loggers and log to the one with the appender you want the message to be directed to. Sounds simple unless your logic in your class would then be complicated.

If you use XML to configure your log4j instead of properties, appenders may have filters applied to them. See the Filter API, it lists the existing filters DenyAllFilter, LevelMatchFilter, LevelRangeFilter, and StringMatchFilter. It describes how filters work at a high level and indicates you may extend the filter class to create a custom filter.

I believe there are some additional filters in the Apache Extras Companion for log4j 1.2.

The Complete Log4j Manual ($) walks through some filter usage if google search does not provide enough information.

 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
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!