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
Metadata
Release files for ctodd-python-lib-logging 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ctodd-python-lib-logging-1.0.0.tar.gz | 5.2 kB | Without provenance | Details for ctodd-python-lib-logging-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ctodd_python_lib_logging-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for ctodd_python_lib_logging-1.0.0-py3-none-any.whl |
Total release size: 10.8 kB
Release files / ctodd-python-lib-logging-1.0.0.tar.gz
| Download URL | ctodd-python-lib-logging-1.0.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a009c9a5e7d1630f72233dbfb7dbaccfe79dc73dd188f808e4a6ccd752151bb6
|
|
BLAKE2b-256 checksum How to use checksums |
ba54aeb938deb32ecf7e4b41a36d7df130569ae08c29523ac9f9a8b9ebf8045a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Release files / ctodd_python_lib_logging-1.0.0-py3-none-any.whl
| Download URL | ctodd_python_lib_logging-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
426fa3d6facecbb12a163c0df531b1bba8354225a94e13808af2073dbd777790
|
|
BLAKE2b-256 checksum How to use checksums |
f03d4843657edacab9dc5ddc06aa2d7eebfd3369179d9c8f7503ccb78a7b5bed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Security for ctodd-python-lib-logging 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.