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.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You just need to set up different loggers for different classes, each with its own file appender
FeralCTOAuthor Commented:
What about categories? Would categories help me accomplish what I want to do?
Categories are history. The methodology i suggested is perfectly standard and requires no special treatment
Mick BarryJava DeveloperCommented:
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");

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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.