Skip to main content

LoggingHandler to write directly into compressed archives and automatically limit disk usage

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 compresses the *.log logfiles directly into a *.gz archive without writing an uncompressed file. You can choose the maximum size of a single *.gz file and the overall maximum size of all compressed logs. This allows you to limit the diskspace usage of your logs directly in the handler. You can also set a header string which will be written at the beginning of every new log file.

Behaviour:

  • Once the file size of the current log reaches the maximum size it gets rotated

  • Once the file sizes of all written logs together exceed the overall maximum size, the oldest logs will be deleted

  • If a header was given, it will be written at the beginning of every log file

  • The current logfile automatically rotates on date change

  • *.gz archives are named: foo.log-2020-07-15.1.gz, foo.log-2020-07-15.2.gz,…

The size limits are not completely strict. Each gzip file will be slightly larger than the maximum size since a gzip file needs to be flushed before closing it, which always adds some more bytes. E.g., when the limit is set to 1 MB, the actual filesize of a compressed log will be around 1.1 MB.

Usage:

There are five parameters:

  • log_path (str): path to the folder where the logs should be stored

  • filename (str): the base name of the logfile mylog

  • single_max_size (int): the maximum size of a single *.gz file in megabytes

  • overall_size (int): the maximum size of all *.gz files in megabytes

  • maximum_days (int): automatically removes logfiles that were modified on a date earlier than maximum_days before today

  • header (str): optional header that is written at the beginning of every logfile

compressed_handler = CompressedLogger(log_path="logs/",
                                      filename="foolog.log",
                                      header="----- version: 1.0.32 -----",
                                      single_max_size=1,
                                      overall_size=5,
                                      maximum_days=7)

Credits

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

History

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.2.9.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

compressedlogger-0.2.9-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: compressedlogger-0.2.9.tar.gz
  • Upload date:
  • Size: 9.7 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.2.9.tar.gz
Algorithm Hash digest
SHA256 66bfba10ca8f2dd5cd3b3c206101d373d9eb05dd6f9ef249fb2bade4e02df734
MD5 6aec01eec476b2fa5b072404ca5ccd8a
BLAKE2b-256 0cd3a62fc40dc7c79d4022c02868def41c1fd054ab7640a9efb884cdd435c3ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: compressedlogger-0.2.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 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.2.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 32c7a649d5474ef84c1f90c0541032a95110efa0c1a1ef27f846cc4332cdbe69
MD5 993142955c16ec040b377c819863c7d9
BLAKE2b-256 35c5c35a0268215221456680460310fc6ff294787a8803e5747e5af9fc41b3c3

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