From 5493f89646bb998919ce070d53b036ddfbb85817 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 10 Jun 2017 21:00:35 +0200 Subject: [PATCH] examples for log file rotation --- logging.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/logging.md b/logging.md index 5381ee7f..e9dcc3b9 100644 --- a/logging.md +++ b/logging.md @@ -20,6 +20,8 @@ A logging configuration file can be specified in the `config` configuration option in the `logging` section. The file format is explained in the [Python Logging Module](https://docs.python.org/3/library/logging.config.html#configuration-file-format). +## Logging to a file + An example configuration to write the log output to the file `/var/log/radicale/log`: ```ini [loggers] @@ -48,3 +50,31 @@ format = %(asctime)s - [%(thread)x] %(levelname)s: %(message)s You can specify multiple **logger**, **handler** and **formatter** if you want to have multiple simultaneous log outputs. + +### Timed rotation of disk log files + +An example **handler** configuration to write the log output to the file `/var/log/radicale/log` and rotate it . +Replace the section `handle_file` from the file logging example: +```ini +[handler_file] +class = handlers.TimedRotatingFileHandler +# Specify the output file and parameter for rotation here. +# See https://docs.python.org/3/library/logging.handlers.html#logging.handlers.TimedRotatingFileHandler +# Example: rollover at midnight and keep 7 files (means one week) +args = ('/var/log/radicale/log', when='midnight', interval=1, backupCount=7) +formatter = full +``` + +### Rotation of disk log files based on size + +An example **handler** configuration to write the log output to the file `/var/log/radicale/log` and rotate it . +Replace the section `handle_file` from the file logging example: +```ini +[handler_file] +class = handlers.RotatingFileHandler +# Specify the output file and parameter for rotation here. +# See https://docs.python.org/3/library/logging.handlers.html#logging.handlers.RotatingFileHandler +# Example: rollover at 100000 kB and keep 10 files (means 1 MB) +args = ('/var/log/radicale/log', 'a', 100000, 10) +formatter = full +```