G. Pape
runit

Name

svlogd - runit's service logging daemon

Synopsis

svlogd [-tv] [-r c] [-R abc] [-l n] [-b n] logs

Description

logs consists of one or more arguments, each specifying a directory.

svlogd continuously reads log data from its standard input, optionally filters log messages, and writes the data to one or more automatically rotated logs.

Recent log files can automatically be processed by an arbitrary processor program when they are rotated, and svlogd can be told to alert selected log messages to standard error.

svlogd runs until it sees end-of-file on standard input or is sent a TERM signal, see below.

Log Directory

A log directory log contains some number of old log files, and the current log file current. Old log files have a file name starting with @ followed by a precise timestamp (see tai64n(8)), indicating when current was rotated and renamed to this file.

A log directory additionally contains the lock file lock, maybe state and newstate, and optionally the file config. svlogd creates necessary files if they don't exist.

Log File Rotation

svlogd appends selected log messages to the current log file. If current has size bytes or more size (or there is a new-line within the last len of size bytes) current is rotated:

svlogd closes current, changes permission of current to 0755, renames current to @timestamp.s, and starts with a new empty current. If svlogd sees num or more old log files in dir, it removes the oldest.

Processor

If svlogd is told to process recent log files, it saves current to @timestamp.u, feeds @timestamp.u through ``sh -c "processor"'' and writes the output to @timestamp.t. If the processor finishes successfully, @timestamp.u is deleted and @timestamp.t is renamed to @timestamp.s, otherwise @timestamp.t is deleted and the processor is started again. svlogd also saves any output that the processor writes to file descriptor 5, and make that output available on file descriptor 4 when it runs processor on the next log file rotation.

A processor is run in the background. If svlogd sees a previously started processor still running when trying to start a new one for the same log, it blocks until the currently running processor has finished successfully. Only the HUP signal works in that situation. Note that this may block any program feeding its log data to svlogd.

Config

On startup, and after receiving a HUP signal, svlogd checks for each log if the configuration file log/config exists, and if so, reads the file line by line and adjusts configuration for log as follows:

If the line is empty, less than two characters long, or starts with a ``#'', it is ignored. A line of the form

ssize
sets the maximum file size of current when svlogd should rotate the current log file to size bytes. Default is 1000000. If size is zero, svlogd doesn't rotate log files. You should set size to at least (2 * len).
nnum
sets the maximum number of old log files svlogd should maintain to num. If svlogd sees more that num old log files in log after log file rotation, it deletes the oldest one. Default is 10.
!processor
tells svlogd to feed each recent log file through processor (see above) on log file rotation. By default log files are not processed.

If a line starts with a -, +, e, or E, svlogd matches the first len characters of each log message against pattern and acts accordingly:

-pattern
the log message is deselected.
+pattern
the log message is selected
epattern
log messages matching pattern are printed to standard error.
Epattern
log messages not matching pattern are printed to standard error.

Initially each line is selected. Deselected log messages are discarded from log.

Pattern Matching

svlogd matches a log message against the string pattern as follows:

pattern is applied to the log message one character by one, starting with the first. A character not a star (``*'') and not a plus (``+'') matches itself. A plus matches the next character in pattern in the log message one or more times. A star before the end of pattern matches any string in the log message that does not include the next character in pattern. A star at the end of pattern matches any string.

Options

-t
timestamp. Prefix each selected line with a precise timestamp (see tai64n(8)) when writing to log or to standard error.
-r c
replace. c must be a single character. Replace non-printable characters in log messages with c. Characters are replaced before pattern matching is applied.
-R abc
replace charset. Additionally to non-printable characters, replace all characters found in abc with c (default ``_'').
-l len
line length. Pattern matching applies to the first len characters of a log message only. Default is 1000.
-b buflen
buffer size. Set the size of the buffer svlogd uses when reading from standard input and writing to logs to buflen. Default is 1024. buflen must be greater than len.

Signals

If svlogd is sent a HUP signal, it closes and reopens all logs, and updates their configuration according to log/config.

If svlogd is sent a TERM signal, or if it sees end-of-file on standard input, it stops reading standard input, processes the data in the buffer, waits for all processor subprocesses to finish if any, and exits 0 as soon as possible.

If svlogd is sent an ALRM signal, it forces log file rotation for all logs with a non empty current log file.

See Also

runsv(8), runsvstat(8), runsvctrl(8), runsvdir(8), runsvchdir(8), runit(8), runit-init(8), multilog(8)

http://smarden.org/runit/

Author

Gerrit Pape <pape@smarden.org>


Table of Contents