% Savelogs -- Yet Another Log Rotator % Jessica L. Parsons % Tue Jan 15 20:43:58 PST 2008 #Savelogs## The **savelogs** program rotates logs, optionally saving the old ones elsewhere and signalling the programs that created the logfiles. ##Description### `/etc/savelogs.conf` tells **savelogs** which logs to rotate, when to rotate them, whether to back them up, and what to do after a log is rotated. The format of the configuration file is a *filename*, followed by a list of commands, with punctuation and case ignored: * `every` {`day`|`week`|`year`} Rotate the log at this time. If you tell it **WEEK** (**YEAR**), the rotation will happen on a sunday (the last sunday of the year). * `save` *n* `in` *directory* Save _n_ old logs in the named directory as `o.`_logfile_. Any existing `o.` file will be renamed to `oo.`_file_ to accomodate the new file (so the old `o.log` becomes `oo.log`, and so on), up to the number of files you want to save. * `touch` _mode_ After rotating the old log, create a new (empty) log with the given _mode_. * `size` _size_ Rotate the log if it gets larger than this size. If you suffix the size with **K**, the size is in kilobytes, and a **M** suffix means megabytes. * `signal` _action_ After rotating a log and `touch`ing it, run this command. **savelogs** attempts to batch `signal`, so that if multiple logs are rotated the actions will only be executed once. For example, the following configuration file /var/adm/syslog EVERY WEEK SAVE 2 IN /var/adm/OLD TOUCH 644 SIGNAL "killall -HUP syslogd" Rotates `/var/adm/syslog` every sunday, creating a new empty file with mode 644, saving two of the old logs in `/var/adm/OLD`, and sending a **HUP** signal to `syslogd` after it's finished. ##Source Code### =[Version 1.5](savelogs-1.5.tar.gz)= Many many many feature changes 1. Allow, globally and on a file by file basis, saving backups to numbered (_NN.file_) instead of dotted (_ooo.file_) names. 2. Allow, globally and on a file by file basis, backup file compression. 3. Set, globally and on a file by file basis, the format of the backup file from _ooo.file_ to _file.ooo_. In addition, the code has been ported to more systems, from recent versions of [freebsd][] ([macos][], to be precise) to modern commercial [linux][]es. =[Version 1.4](savelogs-1.4.tar.gz)= Discard the old handbuilt parser and switch over to using [lex][] and [yacc][]. I wanted to do some tweaking of the features for **savelogs** and decided that it was enough of a pain so that this was the time to discard my hand-built parser for a generated one. =[Version 1.3](savelogs-1.3.tar.gz)= This version allows multiple `SIGNAL`s per file, so I can do something like rotate many syslogs, hup syslogd, then hup a [cwatch][] process if and only if `/var/log/messages` was one of those syslogs. I also made the code more portable by fitting it out with my [autoconfiguration scripts][configure]. **Savelogs** now properly builds on pell, which is an **SLS** Linux system, egypt, which is my primary [Mastodon][] build box, and downbelow, which runs an elderly version of [FreeBSD][]. =[Version 1.1](savelogs-1.1.tar.gz)= The first version under version control. [cwatch]: /~orc/Code/cwatch [configure]: /~orc/Code/configure [mastodon]: /~mastodon [freebsd]: http://www.freebsd.org [lex]: http://dinosaur.compilertools.net/#lex [yacc]: http://dinosaur.compilertools.net/#yacc [macos]: http://www.apple.com/macosx [linux]: http://www.kernel.org