Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am really fed up in not being able to solve the tomcat log rotation problem in one our windows server after putting countless hours in it and after trying out various solutions.

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

Methods tried so far:

  1. cronolog didn't work, no files where being created after setting it up.

  2. Managed to configure log4j with DailyRollingFile appender globally for Tomcat, the log files are being created without extension and are not being rotated.

  3. Tried DatedFileAppender too, but didn't get much success.

  4. Tried log4jna based Windows Event Log appender for log4j, there didn't get success

Please suggest an easy method to finish this task.

like image 812
Raghu GS Avatar asked Nov 10 '11 13:11

Raghu GS


People also ask

Which command can be used to rotate the logs?

logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. Normally, logrotate is run as a daily cron job.

How do I view tomcat logs in Windows?

Apache Tomcat Logs Location in Windows By default, Apache Tomcat logs are stored in the install_dir/logs where the install_dir refers to the Apache Tomcat installation directory. The log files are stored in the logs directory.

What is the service used to rotate log files automatically?

Logrotate is a system utility that manages the automatic rotation and compression of log files. If log files were not rotated, compressed, and periodically pruned, they could eventually consume all available disk space on a system.


1 Answers

Apache Tomcat provides the configuration directory conf, that contains the file server.xml. At the bottom of this file, a line that includes the adjustments valve, called AccessLogValve must be un-commented and changed.

The default valve parameters and patterns can easily be modified through an editor. Your settings for the access log file for example may 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 the Tomcat reference:

The fileDateFormat parameter allows a customized date format in the access log file name. The date format also decides how often the file is rotated. If you wish to rotate every hour, then set this value to: yyyy-MM-dd.HH

like image 118
Costis Aivalis Avatar answered Sep 24 '22 12:09

Costis Aivalis