We have multiple log files like database log, weblog, quartzlog in our application.
Any log from files under package /app/database will go to database log.
Any log from files under package /app/offline will go to quartzlog log.
What we need now is - want to direct the log staments from one of the java file under /app/database to be outputted to quartzlog instead of database log.
How can we select a particular log file in java file?
You need to define the appropriate appender that logs in the desired file. Read this short introduction to see how you can do it.
Then in the configuration file, you can instruct all messages from a specific package to go in the selected appender:
log4j.logger.my.package = DEBUG, myFileAppender
I believe that in log4j only package resolution is possible - you can't use an appender per file or method. You could try to work around this by adding an extra layer on top of log4j or implementing your own appender.
For example, instead of log.debug use:
If you only need to do it from a single method, then the above will be enough. Just instruct the logger proxy package to be logged in a different file.