Skip to main content

LoggingHandler to move logs into gziped archives in a smart way

Project description

CompressedLogger

https://img.shields.io/pypi/v/compressedlogger.svg

This is a logging handler to be used with the standard python logging module. The handler creates a log file with the current logs and automatically moves old log files into zipped archives. You can set how many uncompressed logfiles you want to hold and what timespan they should cover. For example you can set each log file to cover three hours and keep four uncompressed logfiles. When the limit of uncompressed logfiles is reached, the oldest uncompressed file will be moved into a zipped archive file for that day. This way, all logentries for a single day are combined into one zipped file. You can also set a maximum of days to keep the archive files as well as a general size limit for archives. If either one of them is reached, the oldest archives are deleted.

Behaviour:

Using the following configuration: .. code-block:: python

compressed_handler = compressedlogger.CompressedLogger(log_path=”logs/”,

filename=”mylog”, header=”- - version: 1.2.34 - - -“, live_log_minutes=300, live_log_count=3, max_archive_size_mb=3, archive_days=2)

This will rotate the live log every 300 minutes. When started at 21.9.2020 - 10:33h, the first live log file will be named mylog-10:33.log. The first rotation will not be at 15:33, but at 15:00. Log rotation timestamp is calculated from 0:00h and not from the start of the application. Therefore, the next live log will be named mylog-15:00.log. So there will be the log files: mylog-10:33.log, mylog-15:00.log, mylog-20:00.log. Because the live logs rotate on day change, the next rotation will happen at 00:00h and not at 01:00h. Once there are more livelogs than in the max_live_logs configuration, the latest log will be moved into a compressed archive for that day. The header will be written to the top of every archived log. So in this example, there will be the log archive mylog2020-09-21.log.gz which will contain one logfile mylog2020-09-21.log with the content of [header + mylog-10:33.log + mylog-15:00.log + mylog-20:00.log].

Usage:

Parameters: * log_path: where your logs will be stored * filename: name of you logfile * live_log_minutes: timespan that is covered by a single live-log * live_log_count: maximum number of live logs to keep uncompressed * max_archive_size_mb: maximum combined size of archived logs, in megabyte * archive_days: maximum of days to keep log archives * header: this header will be written on top of every archived log

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.3.1 (2020-09-21)

  • rework whole behaviour

0.2.9 (2020-09-10)

  • add new parameter ‘maximum_days’

  • update readme

0.2.8 (2020-07-28)

  • add missing support of logging formatters

  • fix the naming of logfiles if more than one handler writes into a log path

0.2.5 (2020-07-15)

  • updated project information and readme

0.2.0 (2020-07-15)

  • some improvements concerning the log paths and log file names

0.1.0 (2020-07-14)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compressedlogger-0.3.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

compressedlogger-0.3.1-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file compressedlogger-0.3.1.tar.gz.

File metadata

  • Download URL: compressedlogger-0.3.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for compressedlogger-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f8b1f203d5e7746b2349eb4cc160ce5d145d309fc4d253b4fbc7d3ffa0b34592
MD5 cc1b183f82dc3edff66947f90600560e
BLAKE2b-256 21366d59bae99363ce02c2b344a6c973b81208fc2fb48c0bc0ccc073bcb29b07

See more details on using hashes here.

File details

Details for the file compressedlogger-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: compressedlogger-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for compressedlogger-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b9d4805dc3759a229d6187c2d23b6b0fc70f82c8631d1d21a1818bbd0f5d2b96
MD5 8f891c10fad4bc55ba1e0c39f72b894f
BLAKE2b-256 1547df17ec652b2e9f351e18871244d5c5c3493960da4a419368a9e04763bc0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page