0

For some specific reason I need to retain both my app specific log and catalina.log. I have configured log4j to use RollingFileAppender for my app specific logs and it is working fine. Is there any way to use similar logging mechanism for catalina.logs also.

Can I do this by somehow tweaking the logging.properties under conf.

Srivatsa N
  • 2,291
  • 4
  • 21
  • 36
  • I tried one more thing, Followed the steps mentioned in http://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j this was for DailyRollingFileAppender. I tried to change from DailyRollingFileAppender to RollingFileAppender. No Luck – Srivatsa N Jan 30 '13 at 09:39

1 Answers1

1

You can use logrotate. If you run ubuntu. Create this file

/etc/logrotate.d/tomcat

Copy the following contents into the above file

/var/log/tomcat/catalina.out {  
 copytruncate  
 daily  
 rotate 7  
 compress  
 missingok  
 size 5M  

}

Make sure that the path /var/log/tomcat/catalina.out above is adjusted to point to your tomcat’s catalina.out

daily - rotates the catalina.out daily

rotate – keeps at most 7 log files

compress – compresses the rotated files

size – rotates if the size of catalina.out is bigger than 5M

Thats it.

Govil
  • 2,034
  • 20
  • 20
  • am on Linux machine, will it work there too. ? any other options ? Thanks, – Srivatsa N Jan 30 '13 at 03:24
  • I tried the above solution ( the one in the link) on my local machine.Still the files are not rolling. How does system determine which file to Role ? Do I need to edit java.util.logging.config.file for this ? I was trying this in logging.properties, thats my mistake I guess. – Srivatsa N Jan 30 '13 at 05:42
  • java.util.logging.config.file is a system property and logging.properties is an configuration file that decides what to log and rolling settings etc. See this http://java.ociweb.com/mark/programming/JavaLogging.html#Configuration – Govil Jan 30 '13 at 10:25
  • Try the solution that I gave it works, I checked in my linux machine. – Govil Jan 31 '13 at 05:46
  • I did, Thanks a Lot, But on a side note any idea on how to do it using Log4j – Srivatsa N Feb 05 '13 at 11:35
  • create log4j.properties in the project classpath and do the following config. http://stackoverflow.com/questions/1050256/how-can-i-get-log4j-to-delete-old-rotating-log-files.. – Govil Feb 05 '13 at 12:27