Skip to main content

My way python logger configuration

Project description

#clogger

Python logger configuration, my way.

clogger is a library that helps to configure python logging lybrary in the way I like. It helps configuration task such:

  • multiple handlers (several filehandler, a streamhandler)
  • log level setting for one or all handlers

clogger contains two classes - CustomLogger and CustomFormatter - based on default logging library.

CustomFormatter inherit and modify logging.Formatter class in order to split handler names at the last '.', to improve readability of the log.

CustomoLogger class initialize and configure logging library enabling a small set of preconfigured actions.

Installation

Install clogger is as easy as run pip install clogger.

Usage

You can configure log inside your script with few code rows.

from clogger import CustomLogger
from datetime import datetime

now = datetime.now().strftime('%Y%m%d')
thisrunlog = 'thisrunlog_{}.log'.format(now)

logger = CustomLogger(
    handler_name="mylog",
    stream_handler=True,
    file_handler=True,
    filenames=["default.log", thisrunlog],
    level="INFO",
)

In the above example three handlers are defined: one stream handler and two file handlers. After definition, the same logger can be modified, to hack log level of all handlers (of course, the handler must exists in the namespace to be varied):

# changing log level for all the handlers
logger.change_level('DEBUG')

# changine level for some handlers
logger.change_level('DEBUG', ["mylog", "requests"])

Two methods are definied to be immediately call at the start and at the end of a script:

logger.starting_message()

#... a lot of code...

logger.exiting_message()

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

clogger-0.12.4.tar.gz (7.6 kB view details)

Uploaded Source

File details

Details for the file clogger-0.12.4.tar.gz.

File metadata

  • Download URL: clogger-0.12.4.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for clogger-0.12.4.tar.gz
Algorithm Hash digest
SHA256 a40e111973d65566c5c337fbbdb5621680c81494a35b565dcd475363dbd0afe4
MD5 a7c44cdcc710dbb71e14c48d283314d9
BLAKE2b-256 c885f748fa119254bbb1bc3893f5e9fb4b50b923fd515dd538af64b6ef4852b3

See more details on using hashes here.

Supported by

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