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.
Features
- Colors : Main reason for this package was to have a simple logging package that can be used in Windows console and supports ANSI colors.
- Argument parsing : log21's argument parser can be used like python's argparse but it also colorizes the output.
- Logging : A similar logger to logging.Logger but with colorized output and other options such as levelname modifications. It can also decolorize the output if you want to log to a file.
- Pretty printing : Have you ever wanted to colorize the output of the pprint module? log21's pretty printer can do that.
- Tree printing : You can pass a dict or list to log21.tree_print function and it will print it in a tree like structure. Its also colorized XD.
- Any idea? Feel free to open an issue or submit a pull request.
Installation
Well, this is a python package so the first thing you need is python.
If you don't have python installed, please visit Python.org and install the latest version of python.
Then you can install log21 using pip module:
python -m pip install log21 -U
Or you can clone the repository and run:
python setup.py install
Changes
1.5.7
Added log21.tree_print()
function.
Usage Examples:
import log21
log21.print(log21.get_color('#FF0000') + 'This' + log21.get_color((0, 255, 0)) + ' is' + log21.get_color('Blue') +
' Blue' + log21.get_colors('BackgroundWhite', 'Black') + ' 8)')
logger = log21.get_logger('My Logger', level_names={21: 'SpecialInfo', log21.WARNING: ' ! ', log21.ERROR: '!!!'})
logger.info('You are reading the README.md file...')
logger.log(21, 'Here', '%s', 'GO!', args=('we',))
logger.setLevel(log21.WARNING)
logger.warning("We can't log messages with a level less than 30 anymore!")
logger.debug("You won't see this!")
logger.info("Am I visible?")
logger.error(log21.get_colors('LightRed') + "I'm still here ;1")
import log21
from log21 import ColorizingArgumentParser, get_logger, get_colors as gc
parser = ColorizingArgumentParser(description="This is a simple example of a ColorizingArgumentParser.",
colors={'help': 'LightCyan'})
parser.add_argument('test1', action='store', help='Test 1')
parser.add_argument('test2', action='store', help='Test 2')
parser.add_argument('--optional-arg', '-o', action='store', type=int, help='An optional integer')
parser.add_argument('--verbose', '-v', action='store_true', help='Increase verbosity.')
args = parser.parse_args()
logger = get_logger('My Logger', level_names={log21.DEBUG: ' ? ', log21.INFO: ' + ', log21.WARNING: ' ! ',
log21.ERROR: '!!!'})
if args.verbose:
logger.setLevel(log21.DEBUG)
else:
logger.setLevel(log21.INFO)
logger.debug(gc('LightBlue') + 'Verbose mode on!')
logger.debug('Arguments:\n'
'\tTest 1: %s\n'
'\tTest 2: %s\n'
'\tOptional: %s', args=(args.test1, args.test2, args.optional_arg))
logger.info(gc('LightGreen') + args.test1)
logger.info(gc('LightWhite') + 'Done!')
import json
import log21
data = json.load(open('json.json', 'r'))
# Prints data using python's print function
print(data)
# Uses `log21.pprint` to print the data
log21.pprint(data)
# Uses `log21.tree_print` to print the data
log21.tree_print(data)
About
Author: CodeWriter21 (Mehrad Pooryoussof)
GitHub: MPCodeWriter21
Telegram Channel: @CodeWriter21
Aparat Channel: CodeWriter21
License
Donate
In order to support this project you can donate some crypto of your choice 8D
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.