A simple logging package that helps you log colorized messages in Windows console.
Project description
log21
A simple logging package that helps you log colorized messages in Windows console and other operating systems.
Install
To install log21 you can simply use the pip install log21
command:
python -m pip install log21
Or you can clone the repository and run:
python setup.py install
Changes
1.4.4
get_color
function now supports hexadecimal and decimal RGB values.
1.4.5
StreamHandler
can handle new-line characters at the beginning of the message.
1.4.6
ColorizingArgumentParser
added.
You can use ColorizingArgumentParser
to have a colorful ArgumentParser.
1.4.7
Logger.print
added.
You can use Logger.print
to print a message using the current level of the logger class.
It gets printed with any level.
Examples:
from log21 import get_logger, get_colors
logger = get_logger()
logger.warning(get_colors('light red', 'background-white'), 'careful!')
# [21:21:21] [warning] careful!
import log21
logger = log21.get_logger(name='Logger21', level=log21.DEBUG, show_level=False)
logger.debug(log21.get_color('blue') + 'Here we are!')
# [21:21:21] Here we are!
from log21 import ColorizingStreamHandler, Logger, ERROR
logger = Logger('MyLogger')
streamHandler = ColorizingStreamHandler()
logger.addHandler(streamHandler)
logger.log(ERROR, '%sAn', '%serror', '%soccurred!', args=('\u001b[31m', '\x1b[91m', '\033[31m'))
# An error occurred!
from log21 import get_logger, get_colors
logger = get_logger("LOG21", show_time=False)
logger.info('This is', get_colors('#008888') + 'Cyan', get_colors('rst') + 'and this is',
get_colors('000128000', 'BackWhite') + 'Green with White Background' + get_colors('reset') + '!')
# This is Cyan and this is Green with White Background!
logger.info('This is', get_colors('#00efef') + 'Light Cyan', get_colors('rst') + 'and this is',
get_colors('000255000', 'BackLightWhite') + 'Light Green with Light White Background' + get_colors(
'reset') + '!')
# This is Cyan and this is Light Green with Light White Background!
from log21 import ColorizingStreamHandler, Logger, ColorizingFormatter
logger1 = Logger('Logger1')
logger2 = Logger('Logger2')
streamHandler1 = ColorizingStreamHandler(handle_new_line=True)
streamHandler2 = ColorizingStreamHandler(handle_new_line=False)
formatter = ColorizingFormatter('[{levelname}] {message}', style='{')
streamHandler1.setFormatter(formatter)
streamHandler2.setFormatter(formatter)
logger1.addHandler(streamHandler1)
logger2.addHandler(streamHandler2)
logger1.info('\n\n1: Hello World!')
#
#
# [INFO] 1: Hello World!
logger2.info('\n\n2: Hello World!')
# [INFO]
#
# 2: Hello World!
#
About
Author: CodeWriter21 (Mehrad Pooryoussof)
GitHub: MPCodeWriter21
Telegram Channel: @CodeWriter21
Aparat Channel: CodeWriter21
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.