Colorize your console output.
Project description
Colorize your console output.
Provides ConsoleHandler()
for working with logging
module to get colored logging message.
Usage Example
1. Colorize your logging output
# you can just do `from colorlog import *`
import logging, coloredlog
logging.basicConfig(
format='%(asctime)s %(filename)s:%(lineno)d [%(levelname)s] %(message)s',
handlers=[coloredlog.ConsoleHandler()],
level=logging.DEBUG
)
logger = logging.getLogger(__name__)
logger.info('logging started')
logger.debug('debug message')
logger.info('informative')
logger.log(coloredlog.NOTIFY, 'notification')
logger.warning('a warning message')
logger.error('message on error occurred')
try:
raise RuntimeError('An exception!')
except:
logger.exception('Exception:')
logger.critical('THIS IS CRITICAL')
Result on Windows 10
2. Decorate your normal message
from coloredlog.color import *
print(deco('Hello, ', 0x011, bold=True) + reset() + 'world!')
print(deco('Hello, ', reverse=True) + reset() + 'world!')
print(deco('Hello, ', FG_BLUE, bold=True) + reset() + 'world!')
print(deco('Hello, ', FG_YELLOW, BG_GREEN, bold=True) + reset() + 'world!')
print(deco('Hello, ', FG_MAGENTA, bold=True) + reset() + 'w...')
# Simple convenience functions
warning("emmm, seems there is a small proble...")
error('Unknown error!')
For more infomation on parameter rules for deco( ), please refer to the docstring.
Result on Windows 10
3. For intensive use case
Since a complete run-through of deco()
can be a bit time-consuming under intensive use case, you may consider method below to speed up the operation of deco()
from coloredlog.color import *
const_deco = deco('', FG_BLUE, BG_WHITE, bold=True)
# simulates intensive use case
for i in range(10):
print(deco('Hello world for {} times'.format(i), const_deco=const_deco)) # `deco()` will return immediately
print(reset()) # reset to normal color
Result on Windows 10
Tested on
- Windows 10 (python 3.6)
- Ubuntu 16.4.1 (python 3.5)
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
coloredlog-0.2.1.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for coloredlog-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd39deb8789c1ae316d929548432fabb9076c1c6c007ed02c2d2114f0ebaa50d |
|
MD5 | 0d2d23bf05a631b25f92dbee809cc1da |
|
BLAKE2b-256 | 1de91d18c637783e067eb41929d8f6f05b1f9e8709e76d14de272b6942caa16a |