I'm currently logging via the simplest of methods within my servlet using Tomcat. I use the ServletConfig.getServletContext().log to record activity. This writes to the localhost.YYYY-MM-DD.log in $TOMCAT_HOME/logs.
I don't want to get away from the simplicity of this logging mechanism unless absolutely necessary. But I would like to name my log file. Rather than "localhost".YYYY-MM-DD.log, is there a way to have it write to "myAppName".YYYY-MM-DD.log. I know I could create my own mechanism, but again, I looking for simplicity here.
I'm hoping to stay away from a complete framework like Log4j.
For Tomcat 6.x, you can change the logging configuration in conf/logging.properties.
But I prefer a separate configuration with Log4j...
So there is a way via the $TOMCAT_HOME/conf/logging.properties without touching my servlet code...
before...
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler, 5host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
after...
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler, 5host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler, 6localhost.org.apache.juli.FileHandler
then add...
6localhost.org.apache.juli.FileHandler.level = FINE
6localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
6localhost.org.apache.juli.FileHandler.prefix = myAppName.
and add...
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myAppName].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myAppName].handlers = 6localhost.org.apache.juli.FileHandler
and bounce tomcat. This created a $TOMCAT_HOME/logs/myAppName.2008-10-14.log with my simplistic ServletConfig.getServletContext().log() messages only.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.