Skip to main content

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


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.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

rainbowlog-0.2.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file rainbowlog-0.2.2.tar.gz.

File metadata

  • Download URL: rainbowlog-0.2.2.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-1025-azure

File hashes

Hashes for rainbowlog-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d1b2afdc0c7a9d0aa9aa82d16c83630d396eb8f6c55f2297899ba982492ca447
MD5 8064cbbabe3f1a19706a293c1d1aed0b
BLAKE2b-256 c0bbfdf59465180289f14d43ef483623eb296faa359c09e91aa418324e6bd96c

See more details on using hashes here.

File details

Details for the file rainbowlog-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: rainbowlog-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.7.13 Linux/5.13.0-1025-azure

File hashes

Hashes for rainbowlog-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fe2e8f503b25b2dc40178eab7e253ac9e0ef91ece7ffa60c5f9de298eba4daaf
MD5 e27437213c756c86f5db37419ee7fb72
BLAKE2b-256 b801281f7ff85465ab83dd561bb735e7872c65db754c0dccae1f61895afa424e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page