mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #260 from AndreaCrotti/log_refactor
remove unused colors and refactor more how the escaping is done
This commit is contained in:
commit
d57cd81ca6
1 changed files with 16 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
import sys
|
||||
from logging import CRITICAL, ERROR, WARN, INFO, DEBUG
|
||||
from logging import CRITICAL, ERROR, WARN, INFO, DEBUG
|
||||
from logging import critical, error, info, warning, warn, debug
|
||||
from logging import Formatter, getLogger, StreamHandler
|
||||
|
||||
|
|
@ -8,31 +8,25 @@ from logging import Formatter, getLogger, StreamHandler
|
|||
RESET_TERM = u'\033[0;m'
|
||||
|
||||
|
||||
def term_color(code):
|
||||
return lambda text: code + unicode(text) + RESET_TERM
|
||||
def start_color(index):
|
||||
return u'\033[1;{0}m'.format(index)
|
||||
|
||||
|
||||
def term_color(color):
|
||||
code = COLOR_CODES[color]
|
||||
return lambda text: start_color(code) + unicode(text) + RESET_TERM
|
||||
|
||||
|
||||
COLOR_CODES = {
|
||||
'gray': u'\033[1;30m',
|
||||
'red': u'\033[1;31m',
|
||||
'green': u'\033[1;32m',
|
||||
'yellow': u'\033[1;33m',
|
||||
'blue': u'\033[1;34m',
|
||||
'magenta': u'\033[1;35m',
|
||||
'cyan': u'\033[1;36m',
|
||||
'white': u'\033[1;37m',
|
||||
'bgred': u'\033[1;41m',
|
||||
'bggreen': u'\033[1;42m',
|
||||
'bgbrown': u'\033[1;43m',
|
||||
'bgblue': u'\033[1;44m',
|
||||
'bgmagenta': u'\033[1;45m',
|
||||
'bgcyan': u'\033[1;46m',
|
||||
'bggray': u'\033[1;47m',
|
||||
'bgyellow': u'\033[1;43m',
|
||||
'bggrey': u'\033[1;100m',
|
||||
'red': 31,
|
||||
'yellow': 33,
|
||||
'cyan': 36,
|
||||
'white': 37,
|
||||
'bgred': 41,
|
||||
'bggrey': 100,
|
||||
}
|
||||
|
||||
ANSI = dict((col, term_color(code)) for col, code in COLOR_CODES.items())
|
||||
ANSI = dict((col, term_color(col)) for col in COLOR_CODES)
|
||||
|
||||
|
||||
class ANSIFormatter(Formatter):
|
||||
|
|
@ -80,7 +74,7 @@ class DummyFormatter(object):
|
|||
and not sys.platform.startswith('win'):
|
||||
return ANSIFormatter(*args, **kwargs)
|
||||
else:
|
||||
return TextFormatter( *args, **kwargs)
|
||||
return TextFormatter(*args, **kwargs)
|
||||
|
||||
|
||||
def init(level=None, logger=getLogger(), handler=StreamHandler()):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue