How to rotate tomcat logs on Windows? What is the best method?

I'm really tired of not being able to solve the problem of tomcat log rotation on one of our window servers after it took less time and after testing various solutions.

Environment: Java 1.6x, Tomcat 6 (runs as a service), log4j 1.2, Server 2003 32-bit

The methods used.

1) cronolog did not work, without files created after its configuration.

2) To configure log4j using the DailyRollingFile application globally for tomcat, log files are created without an extension and do not rotate.

3) I tried DatedFileAppender too, but did not get much success.

4) Tried log4jna based on Windows Event Log appender for log4j, failed

Please suggest an easy way to complete this task.

+6
source share
3 answers

Apache Tomcat provides the conf configuration directory containing the server.xml file. At the bottom of this file, a line that includes an adjustment valve, called AccessLogValve needs to be commented and modified.

Default valve parameters and templates can be changed through the editor. For example, your settings for an access log file might look like this:

<Valve className="org.apache.catalina.valves.AccessLogValve." directory="logs" prefix="mysite." suffix=".log" pattern='%a %A %b %B %h %l %m %p %q %u %t "%r" %s %U %D %S' resolveHosts="false" rotatable="true" fileDateFormat="yyyy-MM-dd" /> 

This sentence is from a Tomcat link :

"The fileDateFormat parameter allows you to configure the date format in the access log file name. The date format also determines how often the file rotates. If you want to rotate every hour, set this value: yyyy-MM-dd.hh"

+4
source

I finally solved the problem after a long stretch. This time I did not touch the tomcat log configuration. I used a fantastic utility called logrotatewin, which is a reimplementation of logrotate on Windows. I was already familiar with logrotate, so setting up logrotatewin was an easy task. I had to stop tomcat in prerun and run it in postrun to rotate the log to work, because tomcat locks the log file when it works.

+1
source

I was looking for how to rotate Access Valve logs. Of the data that I have collected so far, rotation has simply switched to the next file based on the set fileDateFormat value.

For example, the value "yyyy-MM-dd.HH" will create a new file every hour. But it seems that the files will continue to grow in number if you do not use an external mechanism, like the cron job (on linux), to clear them.

0
source

Source: https://habr.com/ru/post/901209/


All Articles