LinuxCommandLibrary

savelog

Rotate and compress log files

SYNOPSIS

savelog [options] file

PARAMETERS

-m mode
    Sets the file permissions (mode) for the log file. Defaults to 644 (rw-r--r--).

-o
    Overwrite the log file rather than appending to it.

-p
    Use standard output instead of syslog.

-q
    Quiet mode. Suppress non-error messages.

-t
    Adds timestamp to each log entry.

-u
    Use UTC timestamps.
Requires option -t.

-c
    Rotate the log file by copying it to a backup before appending. If -c not specified, then log file is truncated.

-l
    Lock the file before opening and logging.

file
    The path to the log file where output will be saved.

DESCRIPTION

The `savelog` command is a utility designed to simplify the process of saving the output of other commands to a log file, while also incorporating features for log rotation and timestamping. It ensures that only one instance of a command is writing to a log at a time, preventing data corruption or interleaving. The primary use case for `savelog` is in scripts or cron jobs where automated tasks need to generate logs, and those logs need to be managed efficiently. It adds a timestamp to the log file, ensuring that each run is clearly marked. It is particularly useful for services and applications that do not have built-in logging capabilities or where more straightforward log management is desired. `savelog` will optionally compress the log file upon rotation, saving disk space. The command employs file locking mechanisms to prevent concurrent writes from different processes, making it a robust solution for logging in multi-threaded environments.

USAGE EXAMPLES

Example 1: Save the output of a command to a log file with timestamp:
savelog -t /var/log/mycommand.log mycommand

Example 2: Save the output of a command to a log file without timestamp and overwrite it:
savelog -o /var/log/mycommand.log mycommand

Example 3: Save the output of a command to a log file with file locking enabled:
savelog -l /var/log/mycommand.log mycommand

HISTORY

`savelog` likely evolved from the need for a simple, reliable way to log output from shell scripts and cron jobs. Its development focused on ensuring atomic writes and log rotation without requiring complex configuration or dependencies. It provided a more lightweight alternative to more extensive logging frameworks. The command became a standard tool on many Linux systems, providing a consistent way to save outputs to a log file with optional timestamp and some basic log management functionality.

SEE ALSO

logger(1), logrotate(8), tee(1)

Copied to clipboard