Skip to content

Commit

Permalink
use-cases: Logs With Rotation and Pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroscope committed Mar 25, 2017
1 parent 6102f22 commit f94a009
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/use-cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,48 @@ Then restart *rTorrent*, and you should see ``Hello from config.d!``
amongst the initial console messages.


Logs With Rotation and Pruning
------------------------------

The following longer snippet adds logs that don't endlessly grow,
get archived after some days, and are finally deleted after a while.
The time spans for this are set using
``pyro.log_archival.days`` (default: 2) and
``pyro.log_retention.days`` (default: 7).

.. literalinclude:: pimp-my-box/roles/rtorrent-ps/templates/rtorrent/rtorrent.d/15-logging.rc
:language: ini
:start-after: rotating logs
:end-before: YYYY-mm-dd

Log files are time stamped (see ``pyro.date_iso.log_stamp`` and ``pyro.log_stamp.current``).
Full log file paths for different types are created using ``pyro.logfile_path``,
which takes the type as an argument.

.. literalinclude:: pimp-my-box/roles/rtorrent-ps/templates/rtorrent/rtorrent.d/15-logging.rc
:language: ini
:start-after: pyro.log_archival.days
:end-before: open all logs

The ``pyro.log_rotate`` multi-method takes care of calculating a new time stamp,
and rotating all the log files by re-opening them with their new name.
A daily schedule calls this method and thus triggers the rotation.

.. literalinclude:: pimp-my-box/roles/rtorrent-ps/templates/rtorrent/rtorrent.d/15-logging.rc
:language: ini
:start-after: cat = (cfg.logs)
:end-before: Log file archival

Finally, two schedules take care of daily archival (2:00 AM) and pruning (2:10 AM),
passing the command built by ``pyro._logfile_find_cmd`` to ``bash`` for execution.
The ``pyro.log_rotate`` method is used near the end to open log files at startup.

.. literalinclude:: pimp-my-box/roles/rtorrent-ps/templates/rtorrent/rtorrent.d/15-logging.rc
:language: ini
:start-after: pyro_daily_log_rotate
:end-before: END logging


Set a Download to “Seed Only”
-----------------------------

Expand Down

0 comments on commit f94a009

Please sign in to comment.