A small Python library for standardising the same logging functions I keep writing for every script.
Simply clone the repo into your project:
git clone https://github.com/Lut99/logging-py ./logging
or, if you want to be able to stay up-to-date:
git submodule add https://github.com/Lut99/logging-py ./logging
(don't forget to clone your own repository with git clone --recursive
if you do)
Then, you can add:
import logging
at the top of your file.
The following functions are exposed:
-
def pdebug(text: str, end: str = '\n', use_colour: Optional[bool] = None, file: TextIOWrapper = sys.stderr)
-
def pinfo(text: str, end: str = '\n', use_colour: Optional[bool] = None, file: TextIOWrapper = sys.stderr)
-
def pwarn(text: str, end: str = '\n', use_colour: Optional[bool] = None, file: TextIOWrapper = sys.stderr)
-
def perror(text: str, end: str = '\n', use_colour: Optional[bool] = None, file: TextIOWrapper = sys.stderr)
All of them have the same behaviour and arguments (roughly), except that the log levels (and therefore styling) of the statements varies.
text
: The message to display.end
: Something to print at the end of the message. By default, this is a newline.use_colour
: Whether to use colour or not. UseNone
to try and deduce it automagically (default:None
).file
: The file on which to write the message. Defaults to stdout forpdebug
andpinfo
, defaults to stderr forpwarn
andperror
.
Then the script also exposes:
def set_debug(enable: bool)
which allows one to control whether pdebug()
does anything. By default, does not print anything unless set_debug(True)
is called.
Feel free to contribute to the script! Either raise an issue or create a pull request.
This project is licensed under Apache 2.0. See LICENSE for more details.