A pretty and colorful logger to emulate nest.js's logger
Project description
Pretty Logger
Description
This is python package has been developed to emulate the nest.js integrated logger. It allows for colorful terminal logs as well as activating or deactivating debug/warn or error print statements.
Install
pip install pretty-logger
In-code usage
To use it, create an instance of the Logger class within the class you wish to have this logger run for and give it the class's name. Once you have an object for the logger, replace all instances of your print statements to the new object. Now you will be able to decide if that print statement should be of type: log, debug, or error.
Example:
The code before:
class TestClass:
def __init__(self):
print('Object created')
def something(self, number: str) -> int:
print('We are here')
try:
return int(number)
except ValueError as e:
print(e)
return 0
The updated code:
from pretty_logger import Logger
class TestClass:
logger: Logger
def __init__(self):
self.logger = Logger('TestClass')
self.logger.log('Object created')
def something(self, number: str) -> int:
self.logger.debug('We are here')
try:
return int(number)
except ValueError as e:
self.logger.error(e)
return 0
Running a program which has a Pretty Logger
After the pretty logger has been implemented, you can use the following flags when launching your python script to activate the various logs:
--pretty-debug
: Allows for displaying debug/warn logs--pretty-error
: Allows for displaying error logs--pretty-none
: Disables all logs for script
Example:
This will run the script main.py
with all the possible loggers:
python main.py --pretty-debug --pretty-error
Buy me a coffee
If you wish to offer me a coffee, please buy yourself one instead and cheer in my name xD
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
Built Distribution
Hashes for kayer-pretty-logger-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b749d131746b0e24399f998049a13b1d8682926c5cbfdbaa71a603a53d0829d |
|
MD5 | 5dfac8fbd4c0a94883cda8e38d808342 |
|
BLAKE2b-256 | 31868c432fc71596c94612efd8132fcb8c5b2f79e03967346b171a48491fdf04 |
Hashes for kayer_pretty_logger-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f3481235384dd135f3a9714df507f577c3a39df3ce6af9fd5be27c6d162887b |
|
MD5 | f65c950ef8eb54d8a913b8a0967ebb1c |
|
BLAKE2b-256 | b52fcb43004f253e3365ea843c29b3a66b8df9b24871a8e4cd362458ae0e0ff3 |