43

I have a default tomcat installation with no change to the logging configuration. The log files (in particular catalina.out) appear to be getting rolled (daily) correctly.

However as well as the daily logs there is also a catalina.out file, which just continues to grow. This is what I need to fix, ie have it cleared daily (or remove it altogether if possible)

Can someone explain what is going on here and the best best strategy for controlling that log file size?

Just to clarify the output is being written to catalina.out and the daily log simultaneously

-rw-r--r--  1 solr solr   90920663 Jul 18 01:16 logs/catalina.2009-07-18.log
-rw-r--r--  1 solr solr     238010 Jul 18 01:16 logs/catalina.out

Setting swallowOutput appears to not make any difference.

The application being run under tomcat is solr in case that is relevant.

objects
  • 8,637
  • 4
  • 30
  • 38
  • 1
    The first "catalina.out" occurrence is probably wrong. It's "catalina.log" that gets rotated daily. – ceztko Sep 11 '13 at 11:54

5 Answers5

71

Fixed it, turns out the standard logging configuration defines a file logger and also a console logger. The file logger goes to the daily catalina log, and the console logger writes to catalina.out.

Fix was to change in conf/logging.properties:

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

to

.handlers = 1catalina.org.apache.juli.FileHandler

That stops anything getting written to catalina.out

objects
  • 8,637
  • 4
  • 30
  • 38
  • 10
    Just wanted to mention that this does not stop an application which specifies something like this in their log4j.properties file: log4j.rootLogger=DEBUG,stdout,logfile Those still get dumped to stdout and placed in catalina.out. Just something to watch for... – Corey S. Nov 29 '10 at 22:21
  • 2
    Where do the logs go if not logged in catalina.out? I mostly refer catalina.out for debugging and need those logs. – Rakesh Rakshit Aug 04 '17 at 06:41
  • 1
    @RakeshRakshit the exact output file is specifified as part of the paraneters to FileHandler - See [FileHandler](https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/juli/FileHandler.html). Most likely it will end up being catalina.YYYY-MM-DD.txt based on defaults for both FileHandler and tomcat. – YoYo May 14 '18 at 19:22
5

Hi you may want to try this solution

http://java.dzone.com/articles/how-rotate-tomcat-catalinaout

It uses a cronjob (logrotate) to copy, compress and clean your catalina.out and if you have a look at logrotate you will see it has a lot of additional functionality. It does not interfere with the daily logs, unless you configure it do so. I found it helpful when I was confronted with the same problem.

BTW removing the console handler will only affect messages produced by Tomcat.

KJH
  • 2,382
  • 16
  • 26
Rambo Amadeus
  • 51
  • 1
  • 2
  • 2
    When i execute `/usr/sbin/logrotate /etc/logrotate.conf` after configuring `/var/log/tomcat/catalina.out` still it does not solve my problem of rotating the `catalina.out` file – Bhavik Ambani Feb 07 '12 at 06:47
  • Another thing is this will rotate daily. What if I want to rotate as and when the size of the log file reaches to the maximum allocated size ? – Bhavik Ambani Feb 07 '12 at 07:34
3

you can rotate the your catalina.out file by configure :-

Steps:-

  • 1) Goto /etc/logrotate.d and Create file tomcat

  • 2) Paste below line

  • Rotate by size

/opt/OS/OS2/logs/catalina.out {
copytruncate
daily
rotate 30
compress
missingok
size 20M
}

-- size - backup catelina.out if size is greater then 20MB

OR

  • Rotate by Date

/opt/deadpool/apache-tomcat/logs/catalina.out {

copytruncate

dateext

daily

rotate 30

compress

missingok

}

  • rotate - Save last 30 rotation
  • dateext - backup catelina.out everyday
  • daily - Rotation daily basis
  • compress - rotation in compress form
  • missingok - if something is missing in rotation it will create no impect

3) Restart the server

Its work for me :) Hope this will help someone.

Thank you :)

Skyfall
  • 57
  • 8
  • I like this answer the better because it has CR/LF in params (otherwise you can get a 'bad rotation count' for days) and has option for size and date clearly pasted. Btw, point 3 was not required for me (CentoOS 7.x) and lastly you can check if everything suits you via `/usr/sbin/logrotate /etc/logrotate.conf` minding that it will rotate all in the dir (root access required) – Diego1974 Apr 04 '18 at 14:57
  • Yes item 3) restart server is not necessary, see https://unix.stackexchange.com/questions/116136/how-to-make-log-rotate-change-take-effect for details. – Eugene Gr. Philippov Feb 11 '21 at 18:30
2

I had same problem on Ubuntu 11.04 SOLR server and catalina.out file was almost 1GB. After

changing logging.properties:

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

to

.handlers = 1catalina.org.apache.juli.FileHandler

That stops logging to catalina.out

You can find logging.properties file on /etc/tomcat6/ folder for Ubuntu Linux.

Guray Celik
  • 1,281
  • 1
  • 14
  • 13
0

I also noticed my tomcat log folder (/usr/local/tomcat/logs) was quite huge. To check the size of the log folder do the following du -hs /usr/local/tomcat/logs/. To resolved this issue by setting up a cron that would clean the files every night or you can run these commands manually. Here is the shell script that would delete files which are 5 days older

#!/bin/sh
find /usr/local/tomcat/logs -name 'catalina.*.log' -mtime +5 -print0 | xargs -0 rm -f
find /usr/local/tomcat/logs -name 'localhost_access_log.*.txt' -mtime +5 -print0 | xargs -0 rm -f
RC_02
  • 3,146
  • 1
  • 18
  • 20