• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 917
  • Last Modified:

log4j - how to log to multiple files not based on level

I'd like to be able to log multiple types of information in my web application:

1) Performance timings to one log file
2) Typical diagnostic information to another file
3) "Hit" or "site usage" numbers to another file (e.g., how often a particular service is called and by whom)

I'm aware of being able to log to different files based on level, but that's not what I want to do. I want to be able to choose my destination file based on what I'm logging. So, within a single method I may want to log performance timings and diagnostic information - but to different files.

Regards,

Ron
"FeralCTO"
0
FeralCTO
Asked:
FeralCTO
1 Solution
 
sriki77Commented:
You need to use a combination appenders and filters. Basically you can do this in the Log4j configuration itself. you don't need to code them. Probably can use the String match filter (http://logging.apache.org/log4j/docs/api/org/apache/log4j/varia/StringMatchFilter.html)
0
 
CEHJCommented:
You just need to set up different loggers for different classes, each with its own file appender
0
 
FeralCTOAuthor Commented:
What about categories? Would categories help me accomplish what I want to do?
0
 
CEHJCommented:
Categories are history. The methodology i suggested is perfectly standard and requires no special treatment
0
 
objectsCommented:
Instead of having a seperate logger for each class as it typically done, you would have seperate logger based on function

Logger timing= Logger.getLogger("PerformanceTiming");
Logger diagnostics= Logger.getLogger("Diagnostics");
etc.

With the different looger being pointed at different output files in your config (similiar to how you do it for level)

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now