Scroll to navigation

cronolog(1m) cronolog(1m)

NAME

cronolog - write log messages to log files named according to a template

SYNOPSIS

cronolog [OPTION]... template

DESCRIPTION

cronologis a simple program that reads log messages from its input and writesthem to a set of output files, the names of which are constructedusingtemplateand the current date and time. The template uses the same formatspecifiers as the Unixdate(1)command (which are the same as the standard C strftime libraryfunction).

Before writing a messagecronologchecks the time to see whether the current log file is still valid andif not it closes the current file, expands the template using thecurrent date and time to generate a new file name, opens the new file(creating missing directories on the path of the new log file asneeded unless the program is compiled with -DDONT_CREATE_SUBDIRS) andcalculates the time at which the new file will become invalid.

cronologis intended to be used in conjunction with a Web server, such asApache to split the access log into daily or monthly logs. Forexample the Apache configuration directives:


TransferLog "|/usr/bin/cronolog /www/logs/%Y/%m/%d/access.log"
ErrorLog "|/usr/bin/cronolog /www/logs/%Y/%m/%d/errors.log"

would instruct Apache to pipe its access and error log messages intoseparate copies of cronolog, which would create new log files each dayin a directory hierarchy structured by date, i.e. on 31 December 1996messages would be written to


/www/logs/1996/12/31/access.log
/www/logs/1996/12/31/errors.log

after midnight the files


/www/logs/1997/01/01/access.log
/www/logs/1997/01/01/errors.log

would be used, with the directories 1997, 1997/01 and 1997/01/01 beingcreated if they did not already exist. (Note that prior to version 1.2 Apachedid not allow a program to be specified as the argument of theErrorLog directive.)

Options

cronologaccepts the following options and arguments:

-H NAME
maintain a hard link fromNAMEto the current log file.
-S NAME
maintain a symbolic link fromNAMEto the current log file.
maintain a symbolic link fromNAMEto the previous log file. Requires that the--symlinkoption is specified, as cronolog renames the current link to the namespecified for the previous link.
print a help message and then exit.
-p PERIOD
specifies the period explicitly as an optional digit string followedby one of units: seconds, minutes, hours, days, weeks or months. The count cannot be greater than the number of units in the next larger unit, i.e. you cannot specify "120 minutes", and for seconds, minutes and hours the count must be a factor of the next higher unit, i.e you can specify 1, 2, 3, 4, 5, 6, 10, 15, 20 or 30 minutes but not say 7 minutes.
-d PERIOD
specifies the delay from the start of the period before the log fileis rolled over. For example specifying (explicitly or implicitly) aperiod of 15 minutes and a delay of 5 minutes results in the log filesbeing rotated at five past, twenty past, twentyfive to and ten to eachhour. The delay cannot be longer than the period.
create single output log from template, which is not rotated.
-x FILE
write debug messages toFILEor to the standard error stream ifFILEis "-". (See the README file for more details.)
pretend that the starting time isTIME(for debugging purposes).TIME should be something like DD MONTH YYYY HH:MM:SS (the day andmonth are reversed if the american option is specified). If theseconds are omitted then they are taken as zero and if the hours andminutes are omitted then the time of day is taken as 00:00:00(i.e. midnight). The day, month and year can be separated by spaces,hyphens (-) or solidi (/).
Interprete the date part of the starting time the American way (monththen day).
Interprete the date part of the starting time the European way (daythen month). This is the default.
print version information and exit.

Templateformat

Each character in the template represents a character in the expandedfilename, except for date and time format specifiers, which arereplaced by their expansion. Format specifiers consist of a `%'followed by one of the following characters:

%
a literal % character
a new-line character
a horizontal tab character

Time fields:

hour (00..23)
hour (01..12)
the locale's AM or PM indicator
minute (00..59)
second (00..61, which allows for leap seconds)
the locale's time representation (e.g.: "15:12:47")
time zone (e.g. GMT), or nothing if the time zone cannot be determined

Date fields:

the locale's abbreviated weekday name (e.g.: Sun..Sat)
the locale's full weekday name (e.g.: Sunday .. Saturday)
the locale's abbreviated month name (e.g.: Jan .. Dec)
the locale's full month name, (e.g.: January .. December)
the locale's date and time (e.g.: "Sun Dec 15 14:12:47 GMT 1996")
day of month (01 .. 31)
day of year (001 .. 366)
month (01 .. 12)
week of the year with Sunday as first day of week (00..53, where week1 is the week containing the first Sunday of the year)
week of the year with Monday as first day of week (00..53, where week1 is the week containing the first Monday of the year)
day of week (0 .. 6, where 0 corresponds to Sunday)
locale's date representation (e.g. today in April in Britain: "13/04/97")
year without the century (00 .. 99)
year with the century (1970 .. 2038)

Other specifiers may be available depending on the C library'simplementation of thestrftimefunction.

SEEALSO

apache(1m)date(1)strftime(3)environ(5)

More information and the latest version ofcronologcan be obtained from


http://www.ford-mason.co.uk/resources/cronolog/

If you have any suggestions, bug reports, fixes, or enhancements,please mail them to the author.

MoreaboutApache

Documentation for the Apache http server is available from


http://www.apache.org

FUTUREDIRECTIONS

The functionality ofcronologcould be built into Apache, thus saving the overhead of having aprocess per log stream and that of transferring data from the serverprocess to the cronolog process. The main complication is handlingthe case where multiple log streams are written to the same file(template), for example where different virtual servers write to thesame set of log files.

AUTHOR

Andrew Ford <A.Ford@ford-mason.co.uk>

cronologis based on a program calledrotatelogsby Ben Laurie, which is packaged with the Apache web server.

The symbolic linkoption was suggested by Juergen Lesny.

March 1998