Format your python logs with colours based on the log levels.
Project description
Rainbow Log
Format your python logs with colours based on the log levels.
Installation
pip install rainbowlog
Usage
Here's a basic example of a script that logs colorfully to the console, but regularly to a file.
import logging
import rainbowlog
logger = logging.getLogger(__name__)
# This one will write to the console
stream_handler = logging.StreamHandler()
# This one will write to a file
file_handler = logging.FileHandler('output.log')
# Here we decide how we want the logs to look like
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# We want the stream handler to be colorful
stream_handler.setFormatter(rainbowlog.Formatter(formatter))
# We don't want the file handler to be colorful
file_handler.setFormatter(formatter)
# Finally we add the handlers to the logger
logger.addHandler(stream_handler)
logger.addHandler(file_handler)
if __name__ == '__main__':
logger.debug('This is a debug message')
logger.info('This is an info message')
logger.warning('This is a warning message')
logger.error('This is an error message')
logger.critical('This is a critical message')
Docs
You can find the documentation here
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
rainbowlog-0.2.1.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file rainbowlog-0.2.1.tar.gz
.
File metadata
- Download URL: rainbowlog-0.2.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.7.13 Linux/5.13.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79ec40cbe75824ec0fba106109d8ce396aca095e133912907c72edf8c6ca7966 |
|
MD5 | 109014dc9bdd5915f2679d70a25d273b |
|
BLAKE2b-256 | 444315a357e406c03accb4cdef9b252149b745a2081cc7bf11e6b019f7c67e42 |
File details
Details for the file rainbowlog-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: rainbowlog-0.2.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.7.13 Linux/5.13.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7820f6491abf7d0ee80c098bafec7750c4a005dfdd5adb9b350bb639fbf14ef4 |
|
MD5 | 808e495667022b5d9f0a2d061e56623c |
|
BLAKE2b-256 | dffb14eceb4347934c6564f8fc99b9c18150e55e39ff762b4b06383bf019543a |