Elegant Console Logger for Python
From PyPI
pip install consoly
From Github
pip install git+https://github.com/OAlienO/consoly.git
from consoly import consoly
consoly.critical('Bomb!!')
consoly.error('Oh shit...')
consoly.warning('Chill')
consoly.info('Just some information')
consoly.debug('Fuck bugs')
from consoly import consoly
consoly.level = consoly.DEBUG
consoly.defaults = { 'badge': True, 'time': True }
consoly.critical('Bomb!!')
consoly.error('Oh shit...')
consoly.warning('Chill')
consoly.info('Just some information')
consoly.debug('Fuck bugs')
type | level | alias |
---|---|---|
critical | 50 | consoly.CRITICAL |
error | 40 | consoly.ERROR |
warning | 30 | consoly.WARNING |
info | 20 | consoly.INFO |
debug | 10 | consoly.DEBUG |
consoly.types['success'] = {
'level': 25,
'color': Color.green,
'icon': '✔'
}
consoly.level = consoly.SUCCESS
consoly.success('it works')
default instance consoly
is created by Consoly(FancyFormatter())
default to 0
( print every messages )
consoly.level = consoly.ERROR
default to {}
this is the default options pass to formatter
consoly.defaults = { 'badge': True }
see type of levels
see Formatter
default formatter is FancyFormatter
option for FancyFormatter
# set option default
consoly.defaults = { 'badge': True, 'time': True, 'short': True }
consoly.debug('hello')
# set option directly
consoly.debug('hello', badge = True, time = True, short = True)
consoly.formatter.file = open('service.log', 'w')
from consoly import Formatter
class MyFormatter(Formatter):
def format(self, text, typeData, formatData):
name = typeData['name']
color = typeData['color']
bold = formatData.get('bold', False)
if bold: color = color.bold
self.write(f'{color.paint(name)} - {text}')
consoly.formatter = MyFormatter()
For example consoly.error('test', testOption = 10)
{
'name': 'error',
'level': 40,
'color': Color.red,
'icon': '✖'
}
{
'testOption': 10
}