0
votes

I have a servlet and I want to log in the file: catalina-< date >.log. The configuration file log4j.properties (located in catalina.home/lib) is the same as in the http://tomcat.apache.org/tomcat-6.0-doc/logging.html (log4j paragraph):

log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.
log4j.appender.CATALINA.Append=true
log4j.appender.CATALINA.Encoding=UTF-8
# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

The problem is that it doesnt log in the catalina-< date >.log but in the catalina. It appears that the appender is not configured properly. The file catalina appears to be created from log4j.appender.CATALINA.File=${catalina.home}/logs/catalina. in the configuration.

Can anyone help me with this problem?

1
Where is your log4j.properties file? The file catalina.out comes from Tomcat's startup scripts and is the recipient of messages printed to standard output -- it's got nothing to do with log4j. - Christopher Schultz
This is not true. I have also a configuration for the stdout, which prints the messages in the console, but not in the file of logging. - pokeRex110
Tomcat's startup scripts redirect stdout to CATALINA_BASE/logs/catalina.out. If you specify the same path for a log4j appender's file, one will clobber the other. I highly recommend against your strategy shown above. - Christopher Schultz
Ok, but do you have any solution for that? I want to add appenders to my loggers in the application, and everything that is logged from them, to log in the catalina.out (catalina-<date>.log). - pokeRex110
What is your deployment environment? Win32 or *NIX? Also, how to you launch Tomcat? (The solution may depend on how you do things). - Christopher Schultz

1 Answers

1
votes

If you want to rotate logs/catalina.out on win32 when using the startup scripts to launch Tomcat, one option is to install a log-ratating logger such as chronolog (which might be a *NIX-only thing) and then modify catalina.out to pipe standard output to that process instead of redirecting to a file.

Update: A better option (in general on win32) is probably to use Tomcat's service installer and run Tomcat as a service, but I don't believe it makes things any easier to rotate your log file.

The best option of course is not to write to standard out in the first place to avoid ever needing to rotate this log file.