A simple logging utility.
To install the package locally use the following:
pip install get-loggy
- Color support
- Custom color support (advanced)
- Add additional logging levels
- Optional log stream vs. log file
- Log record format
- Package level logging
Loggy exists as a simple interface for some standard logging in Python. This is done at the package level, not by name.
A basic logger may look like this, defaulting to the "info" level logging.
from loggy import loggy
log = loggy.get_loggy()
log.info("Something")
>>> 2022-06-21 20:16:39 PM PDT | INFO | Something | (<stdin>:1:<module>) |
Colors are supported as well, though not for use with log files. Color and log files are mutually exclusive, as the color codes would clutter the logs.
log = loggy.get_loggy(use_color=True)
File handlers are initiated using a dictionary of configurations for the file,
this gives more granular control over file based logging. This is passed
directly to the FileHandler()
instantiation.
The below example creates a log file with append mode.
file_config = {"filename": "some-log-file.log", "mode": "a"}
log = loggy.get_loggy(log_file=file_config)
Custom colors can be created or added along with custom logging levels.
See the conftest.py
for an example of custom formatter
and 'test_loggy.py' to see how the colors are added
for a custom logging level.
Pytest is used as the test runner. To install and run tests
use the requirements-dev.txt
and execute with pytest
.
Note: Use a virtual environment. The steps to create one are left to the user, there are many packages that accomplish this.
pip install -r requirements-dev.txt
pytest