logging: Better colors
Inspired by https://github.com/borntyping/python-colorlog INFO had no colors. You can run weboob/tools/log.py to test them.
This commit is contained in:
parent
24aea160b1
commit
a330b08262
1 changed files with 12 additions and 6 deletions
|
|
@ -17,10 +17,11 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from logging import Filter, Formatter, getLogger as _getLogger
|
from logging import Filter, Formatter, getLogger as _getLogger
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['getLogger', 'createColoredFormatter', 'settings']
|
__all__ = ['getLogger', 'createColoredFormatter', 'settings']
|
||||||
|
|
||||||
|
|
@ -29,9 +30,9 @@ RESET_SEQ = "\033[0m"
|
||||||
COLOR_SEQ = "%s%%s" + RESET_SEQ
|
COLOR_SEQ = "%s%%s" + RESET_SEQ
|
||||||
|
|
||||||
COLORS = {
|
COLORS = {
|
||||||
'DEBUG': COLOR_SEQ % "\033[36m",
|
'DEBUG': COLOR_SEQ % "\033[1;36m",
|
||||||
'INFO': "%s",
|
'INFO': COLOR_SEQ % "\033[32m",
|
||||||
'WARNING': COLOR_SEQ % "\033[1;1m",
|
'WARNING': COLOR_SEQ % "\033[1;33m",
|
||||||
'ERROR': COLOR_SEQ % "\033[1;31m",
|
'ERROR': COLOR_SEQ % "\033[1;31m",
|
||||||
'CRITICAL': COLOR_SEQ % ("\033[1;33m\033[1;41m"),
|
'CRITICAL': COLOR_SEQ % ("\033[1;33m\033[1;41m"),
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +45,7 @@ settings = defaultdict(lambda: None)
|
||||||
def getLogger(name, parent=None):
|
def getLogger(name, parent=None):
|
||||||
if parent:
|
if parent:
|
||||||
name = parent.name + '.' + name
|
name = parent.name + '.' + name
|
||||||
logger = _getLogger(name)
|
logger = _getLogger(name)
|
||||||
logger.settings = settings
|
logger.settings = settings
|
||||||
return logger
|
return logger
|
||||||
|
|
||||||
|
|
@ -77,3 +78,8 @@ def createColoredFormatter(stream, format):
|
||||||
return ColoredFormatter(format)
|
return ColoredFormatter(format)
|
||||||
else:
|
else:
|
||||||
return Formatter(format)
|
return Formatter(format)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
for levelname, cs in COLORS.items():
|
||||||
|
print(cs % levelname, end=' ')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue