Skip to main content

Python Library to quickly create logging handlers

Project description

Python Logging Helper

Python library to quickly create logging handlers. Supports logging to the console as well as to file using a syslog style output format.

Installation

The package is available on PyPi or can be installed manually using the why/tar.gz file attached to the release.

pip3 install logging_helper

Introduction

This library provides a function called "create_logger" that will create and return a logging handler that can be used in your application. The "create_logger" function can be passed a series of different settings to manipulate the default Python logging handler.

Examples

>>> from logging_helper import create_logger
>>> logger = create_logger(console=True)
>>> logger.warning('test')
2022-11-09 16:09:21,210 - root - WARNING - test
>>>
>>> logger.debug('test debug')
>>> ### Note no output! Default is set to WARNING and above
>>>
>>> logger = create_logger(console=True, console_level='DEBUG')
>>> logger.debug('test debug')
2022-11-09 16:11:13,268 - root - DEBUG - test debug
>>> 
>>> logger2 = create_logger(console=True, console_level='DEBUG', name='log2')
>>> logger2.info('logger2 info!')
2022-11-09 16:12:23,358 - log2 - INFO - logger2 info!
>>> logger.info('logger1 info!')
2022-11-09 16:12:35,510 - root - INFO - logger1 info!

In the examples above, you can create multiple loggers with different names. If a name is not provided, the logger takes on the 'root' logger for Python. Replacing the 'root' logger will replace the default logging in python and affects other modules. If you set your logger to debug and start seeing messages from other modules you weren't expecting, provide a name value to your logger.

Parameters

Parameter Default Description
console_level 'INFO' (str) Set the logging level for the console
console True (bool) Enable / Disable logging to the console
log_file '' (str) Set the file to log to (blank means none)
file_level 'WARNING' (str) Set the logging level for the file
file_mode 'a' (str) Feeds into the file mode 'a' for append, 'w' for overwrite
name '' (str) Name for the logger. Blank will replace the root logging handler
syslog False (bool) Send messages to the local system logger
syslog_script_name '' (str) Name to include when using the local system logger
log_file_vars [] (list) list of variables that can be used to create the log file names
log_file_retention_days 0 (int) Specify the max number of days to retain the log files
propagate False (bool) If set to true, the named loggers will also be processed by the root logger. Generally leave false

Release Notes

v1.0.2
- Moved console level to the 1st parameter. Make it quicker and easier to create a console logger - Chaned default console level to INFO from WARNING. This is what I typically end up using anyway - Updated the home page to our new logging_handler page: https://www.learningtopi.com/python-modules-applications/python_logging_handler/ - Allow passing static values DEBUG, INFO, WARNING, ERROR and CRITICAL from the logging module (or you may import from this library)

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

logging_handler-1.0.7.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

logging_handler-1.0.7-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file logging_handler-1.0.7.tar.gz.

File metadata

  • Download URL: logging_handler-1.0.7.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for logging_handler-1.0.7.tar.gz
Algorithm Hash digest
SHA256 f6f7d4cdeb46f00621b387af71278566b88ff647bb07ded6702898bf8d2429c8
MD5 83e4e3befaa7c40d91bb54827e12e120
BLAKE2b-256 5e96864d2fca6395e73c7acd818cf0385992ab726d1c5e8b234a3b6e818d6c8f

See more details on using hashes here.

File details

Details for the file logging_handler-1.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for logging_handler-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f185264a59dd51d9bc188f64ecf956e28892b562264adf50e64e538b390770f8
MD5 604c0592d0cd6fddbd29fe054a3ff955
BLAKE2b-256 bc7eea926777d0f02132e43013befc9597cc6b12007409a8ad1baa426e246c74

See more details on using hashes here.

Supported by

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