I finally decided to dig though the web and put this extremely basic skill into my bag of known tricks.
- If you use log4j, do not waste your time reading the instructions for JULI when you land on the page in Tomcat's documentation which talks about logging.properties file etc.
- Everything that you need to do in order to send the logs to a separate file can be done in log4j.properties.
- Unless you are looking to do something really advanced, in which case you should use log4j.xml file.
- You can read more about that in this Log4j tutorial with Tomcat examples.
- Here's the basic blurb (+/-) that you can throw in with minimal edits to get the job done.
- Use this blurb to direct the output from a particular package or a class to the appender you have created for the new separate file.
# Redirect the logs from an entire package
log4j.logger.com.my.packageName=ERROR, yourAppenderNameGoesHere
# Redirect logs from only a specific class
log4j.logger.com.my.packageName.MyClass=DEBUG, yourAppenderNameGoesHere
# Set the additivity flag to false if you do NOT want the logs to show up redundantly in log files that the parent loggers point to
log4j.additivity.com.my.packageName=false
log4j.additivity.com.my.packageName.MyClass=false
- By the way, do NOT make the mistake of putting the name of your appender as one of the values in the following line of your log4j.properties file.
# don't change this
log4j.rootLogger=INFO, blah, blah,yourAppenderNameGoesHere