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

Release notes can now be found in the release notes folder.

Changing Logging Level

As of v1.0.8, two functions, "update_console_level" and "update_file_level" have been added. To change the logging level on the fly:

>>> from logging_helper import create_logger, update_console_level
>>> logger = create_logger(console=True)
>>> update_console_level(logger, 'info')

CustomLogger class

As of v1.0.8, a CustomLogger class was added. This performs the same function as using create_logger, however rather than requiring a separate function to update logging levels, the class includes a "console_level" and "file_level" function that can be used. The class also utilizes threading to enable old logfile cleanup.

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logging_handler-1.0.10-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logging_handler-1.0.10.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for logging_handler-1.0.10.tar.gz
Algorithm Hash digest
SHA256 df14bbe19e5c91132da573246caaaf3bcfd8c52ba6e724b92352bdb1c5de7dce
MD5 517db33ab996a94eea7598e288e25647
BLAKE2b-256 0d260e5f9b23957965b86096f07d4a13f08bbc48b6d68bb6341127e57e9b38db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for logging_handler-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 b5b1b83fd760c56630843bad8148b518b1bc7b23ba9bdba5ec6dc7553b789d29
MD5 47251795c7ddbf3454fa49ff6d5a2f18
BLAKE2b-256 7f1a311b6d07315da436fd253bd866afa66ac2815140170ecb0dda694251cb54

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