cronolog enhancements

As I use cronolog a lot - mostly for rotating mid-size to huge Tomcat / JBoss console logs - I started missing some
features that would be nice to have for todays needs. The latest official stable release is dated 2002-01-24, so it
is over 10 years old. There is nothing wrong with that, of course, but IT world changed quite a bit since then...

So, as an example, support for large files (with large meaning >2GB) is missing in the 1.6.2 code base. That one
is quite crucial (distributions usually patch the code base to fix this, so no need to worry in most cases).

Another thing is that whenever cronolog opens a log file for writing, it is (by design) opened the same way as just
using ">" redirection in bash. That means there is no way for logrotate, gzip or whatever to catch the current file
without causing trouble (deleted file without freeing disk space ... does that sound familiar ?).
The longer the time period for a given log file and the more log file size matters, special care has to be taken to
manage log archiving or compression.

Well yes there are ways like "cat </dev/null >file" or some logrotate copytruncate setups for getting around that.
You could even do a little fd magic to restore the active log file's contents after accidentally deleting it, but to me
all of this is just working around issues that are better to be avoided in the first place.

Being faced with this over and over again, some time ago I decided to just enhance cronolog. There is a cool 1.7.0
beta around since some time (~2003) that already got some nice patches, so I used that as a foundation.

My patch adds the following:

- fix "cast to pointer from integer of different size" warnings when compiling on 64bits
- fix segfault if using undefined long options (try "cronolog --unknownoption" on a glibc based system)
- add "-f" switch to force immediate flushing and closing the log file after writing to it
- add "-c" switch to automatically gzip compress the log file as soon as a new one is started

To download enhanced cronolog packages for popular linux distributions:

Please visit the openSuSE Build Service for SLES, RHEL, CentOS, openSuSE and Fedora packages:

alternatively, search for "cronolog" on

To build enhanced cronolog yourself:

  Patch cronolog 1.7.0 (will give you 1.7.2):

     1. Get cronolog 1.7.0 beta from the official cronolog web site
     or a copy stored here
     either way the MD5 checksum is 4a53cc3d44984b292f33b73da365cd3e

     2. Get patch
     cronolog-1.7.0_mde5.patch (MD5 checksum is 4274cbc216d930423b53f7303d583ee4)

     3. Patch cronolog
     being in cronolog-1.7.0 directory, issue the following command:
     patch -p1 < /path/to/cronolog-1.7.0_mde5.patch
     where "/path/to" of course is the path to your copy of the patch.

configure the sources:

     ./configure --enable-zlib
     (zlib-devel is required to build with compression support)

build the binary:


install the binary:

     make install

     -OR, if you prefer-

     just copy the cronolog binary from ./src to the destination you want

To use enhanced cronolog:

* use -f to allow for the logfile to be taken away while still in use (logrotate, cp, mv, whatever)
* use -c to compress old logfiles (no need to use additional scripts or logrotate then)

Well, for the sake of completeness:
-c and -r are somewhat mutually exclusive to make sense. So just use one of them.

if everything worked, cronolog should show this help instructions:

usage: ./cronolog [OPTIONS] logfile-spec

   -H NAME,   --hardlink=NAME maintain a hard link from NAME to current log
   -S NAME,   --symlink=NAME  maintain a symbolic link from NAME to current log
   -P NAME,   --prev-symlink=NAME  maintain a symbolic link from NAME to previous log
   -l NAME,   --link=NAME     same as -S/--symlink
   -f         --flush         immediately close fd after writing log content
   -c         --compress      compress old (rotated) log files (disables -r)
   -h,        --help          print this help, then exit
   -p PERIOD, --period=PERIOD set the rotation period explicitly
   -d DELAY,  --delay=DELAY   set the rotation period delay
   -o,        --once-only     create single output log from template (not rotated)
   -x FILE,   --debug=FILE    write debug messages to FILE
                              ( or to standard error if FILE is "-")
   -r,        --helper=SCRIPT post rotation helper script to fork exec on old files
                              ( will be called like "SCRIPT <oldlog>" )
                              ( not tested on windows )
   -G,        --helper-arg=ARG argument passed to rotation helper script
   -u USER,   --set-uid=USER  change to USER before doing anything (name or UID)
   -g GROUP,  --set-gid=GROUP change to GROUP before doing anything (name or GID)
   -a,        --american         American date formats
   -e,        --european         European date formats (default)
   -n,        --no-alarm      wait to rotate logs and create new ones until there is traffic
   -s,    --start-time=TIME   starting time
   -z TZ, --time-zone=TZ      use TZ for timezone
   -V,      --version         print version number, then exit

in case of questions or comments please fell free to drop me a line at burbon04 <at> gmx <dot> de

- Maximilian