Python utilities used for logging
Project description
Christopher H. Todd's Python Library For Configuring Logging
The ctodd-python-lib-logging project is responsible for configuring the logging for python scripts. Will set up the level, format of the messages, and the stream.
Table of Contents
Dependencies
Python Packages
- N/A
Libraries
loggers.py
Library for getting loggers of specific configurations in Python. This will utilize Pythons built-in logging library and will return an instance of logging that can be implemented in any code that already implements the logging class.
Functions:
def get_stdout_logging(
log_level=logging.INFO,
log_msg_fmt="%(asctime)s.%(msecs)03d %(levelname)s %(message)s",
log_date_fmt="%a, %d %b %Y %H:%M:%S",
log_prefix=None,
):
"""
Purpose:
Get Logger to standard out.
Args:
log_level (log level from logging): Minimum level for messages to log
log_msg_fmt (String): Mesage format for all logs with variable
substitution for known logging options
log_date_fmt (Stringg): Dateformat to append to message
log_prefix (String): prefix to append to message
Return:
logging (Python logging object): Configured logging object
Examples:
>>> logging = get_stdout_logging()
or
>>> logging =\
get_stdout_logging(
log_level=logging.DEBUG,
log_prefix='[test_script]: '',
)
"""
def get_file_logger(
log_file=None,
log_filemode="a",
log_level=logging.INFO,
log_msg_fmt="%(asctime)s %(levelname)s %(message)s",
log_date_fmt="%a, %d %b %Y %H:%M:%S",
log_prefix=None,
):
"""
Purpose:
Get Logger to file
Args:
log_level (log level from logging): Minimum level for messages to log
log_msg_fmt (String): Mesage format for all logs with variable
substitution for known logging options
log_date_fmt (Stringg): Dateformat to append to message
log_prefix (String): prefix to append to message
Return:
logging (Python logging object): Configured logging object
Examples:
>>> logging = get_file_logger()
or
>>> logging =\
get_file_logger(
log_level=logging.ERROR,
prefix='[test_script]: '',
log_file='./script_im_writing.log'
)
"""
def clear_log_handlers():
"""
Purpose:
Remove previous log handlers and configurations. This
will ensure that any new logging that is configured
will take precedence, as logging is first setting
is not overwritten.
Args:
N/A
Return:
N/A
"""
Example Scripts
Example executable Python scripts/modules for testing and interacting with the library. These show example use-cases for the libraries and can be used as templates for developing with the libraries or to use as one-off development efforts.
example_stdout_logger.py
Example Logger. Configure to Output to CLI
Notes
- Relies on f-string notation, which is limited to Python3.6. A refactor to remove these could allow for development with Python3.0.x through 3.5.x
TODO
- Unittest framework in place, but lacking tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ctodd-python-lib-logging-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a009c9a5e7d1630f72233dbfb7dbaccfe79dc73dd188f808e4a6ccd752151bb6 |
|
MD5 | 8a1b13bb2091b1badd614c4bb8256a78 |
|
BLAKE2b-256 | ba54aeb938deb32ecf7e4b41a36d7df130569ae08c29523ac9f9a8b9ebf8045a |
Hashes for ctodd_python_lib_logging-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 426fa3d6facecbb12a163c0df531b1bba8354225a94e13808af2073dbd777790 |
|
MD5 | 181be06b8a502be2442e16bb959d5bca |
|
BLAKE2b-256 | f03d4843657edacab9dc5ddc06aa2d7eebfd3369179d9c8f7503ccb78a7b5bed |