Usually you should only log the activity you care about and should configure the program to be less verbose if possible.
As suggested, using logrotate is the usual way of dealing with logfiles. But instead of adding content to /etc/logrotate.conf
you should add your own job to /etc/logrotate.d/
, otherwise you would have to look at more diffs of configuration files during release upgrades.
Here is an example I created for a php script:
/var/log/some-php-app/*.log {
daily
rotate 10
delaycompress
compress
notifempty
missingok
}
/var/log/some-php-app/*.log
- Is the path where the log file(s) is located and it's name. As you can see, you can also use wildcards to apply the rule to more than one logfile.
- daily - Rotates logfiles daily. Alternatives: hourly, weekly, monthly, yearly, maxsize, maxage
- rotate count - Files are rotated count times before being removed or mailed to the address specified in a mail directive.
- delaycompress - Postpones compression of the previous log file to the next rotation cycle.
- compress - Compresses old versions of log files with gzip. You can use
zless
instead of less
to view the files.
- notifempty - Does not rotate the log if it is empty.
- missingok - Goes on to the next rotate job without issuing an error message, when the log file is missing.
Have a look at the logrotate manpage for more options.
logrotate
(and is installed by default in Ubuntu). I don't have familiarity with configuring it, though.