diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:27:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:27:18 +0000 |
commit | f7f20c3f5e0be02585741f5f54d198689ccd7866 (patch) | |
tree | 190d5e080f6cbcc40560b0ceaccfd883cb3faa01 /source/tutorials/log_rotation_fix_size.rst | |
parent | Initial commit. (diff) | |
download | rsyslog-doc-f7f20c3f5e0be02585741f5f54d198689ccd7866.tar.xz rsyslog-doc-f7f20c3f5e0be02585741f5f54d198689ccd7866.zip |
Adding upstream version 8.2402.0+dfsg.upstream/8.2402.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | source/tutorials/log_rotation_fix_size.rst | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/tutorials/log_rotation_fix_size.rst b/source/tutorials/log_rotation_fix_size.rst new file mode 100644 index 0000000..d2d1570 --- /dev/null +++ b/source/tutorials/log_rotation_fix_size.rst @@ -0,0 +1,60 @@ +Log rotation with rsyslog +========================= + +*Written by Michael Meckelein* + +Situation +--------- + +Your environment does not allow you to store tons of logs? You have +limited disc space available for logging, for example you want to log to +a 124 MB RAM usb stick? Or you do not want to keep all the logs for +months, logs from the last days is sufficient? Think about log rotation. + +Log rotation based on a fixed log size +-------------------------------------- + +This small but hopefully useful article will show you the way to keep +your logs at a given size. The following sample is based on rsyslog +illustrating a simple but effective log rotation with a maximum size +condition. + +Use Output Channels for fixed-length syslog files +------------------------------------------------- + +Lets assume you do not want to spend more than 100 MB hard disc space +for you logs. With rsyslog you can configure Output Channels to achieve +this. Putting the following directive + +:: + + # start log rotation via outchannel + # outchannel definition + $outchannel log_rotation,/var/log/log_rotation.log, 52428800,/home/me/./log_rotation_script + # activate the channel and log everything to it + *.* :omfile:$log_rotation + # end log rotation via outchannel + +to rsyslog.conf instruct rsyslog to log everything to the destination +file '/var/log/log\_rotation.log' until the give file size of 50 MB is +reached. If the max file size is reached it will perform an action. In +our case it executes the script /home/me/log\_rotation\_script which +contains a single command: + +:: + + mv -f /var/log/log_rotation.log /var/log/log_rotation.log.1 + +This moves the original log to a kind of backup log file. After the +action was successfully performed rsyslog creates a new +/var/log/log\_rotation.log file and fill it up with new logs. So the +latest logs are always in log\_rotation.log. + +Conclusion +---------- + +With this approach two files for logging are used, each with a maximum +size of 50 MB. So we can say we have successfully configured a log +rotation which satisfies our requirement. We keep the logs at a +fixed-size level of 100 MB. + |