mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] don't circumway logging module
This commit is contained in:
parent
f41eb29953
commit
23276c6941
3 changed files with 18 additions and 16 deletions
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
import re
|
||||
import errno
|
||||
import logging
|
||||
import argparse
|
||||
from json import dumps as json_encode
|
||||
|
||||
|
@ -30,14 +31,14 @@ class LogQueues(dict):
|
|||
pass
|
||||
|
||||
|
||||
class APIQueueHandler(log.Handler):
|
||||
class APIQueueHandler(logging.Handler):
|
||||
"""
|
||||
A handler class which store logging records into a queue, to be used
|
||||
and retrieved from the API.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
log.Handler.__init__(self)
|
||||
logging.Handler.__init__(self)
|
||||
self.queues = LogQueues()
|
||||
|
||||
def emit(self, record):
|
||||
|
@ -673,7 +674,7 @@ class Interface(BaseInterface):
|
|||
|
||||
# Attempt to retrieve log queues from an APIQueueHandler
|
||||
if log_queues is None:
|
||||
handler = log.getHandlersByClass(APIQueueHandler, limit=1)
|
||||
handler = logging.getHandlersByClass(APIQueueHandler, limit=1)
|
||||
if handler:
|
||||
log_queues = handler.queues
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
|||
import errno
|
||||
import getpass
|
||||
import locale
|
||||
import logging
|
||||
from argparse import SUPPRESS
|
||||
from collections import OrderedDict
|
||||
|
||||
|
@ -142,7 +143,7 @@ def get_locale():
|
|||
|
||||
# CLI Classes Implementation -------------------------------------------
|
||||
|
||||
class TTYHandler(log.StreamHandler):
|
||||
class TTYHandler(logging.StreamHandler):
|
||||
"""TTY log handler
|
||||
|
||||
A handler class which prints logging records for a tty. The record is
|
||||
|
@ -159,17 +160,17 @@ class TTYHandler(log.StreamHandler):
|
|||
|
||||
"""
|
||||
LEVELS_COLOR = {
|
||||
log.NOTSET: 'white',
|
||||
log.DEBUG: 'white',
|
||||
log.INFO: 'cyan',
|
||||
log.SUCCESS: 'green',
|
||||
log.WARNING: 'yellow',
|
||||
log.ERROR: 'red',
|
||||
log.CRITICAL: 'red',
|
||||
logging.NOTSET: 'white',
|
||||
logging.DEBUG: 'white',
|
||||
logging.INFO: 'cyan',
|
||||
logging.SUCCESS: 'green',
|
||||
logging.WARNING: 'yellow',
|
||||
logging.ERROR: 'red',
|
||||
logging.CRITICAL: 'red',
|
||||
}
|
||||
|
||||
def __init__(self, message_key='fmessage'):
|
||||
log.StreamHandler.__init__(self)
|
||||
logging.StreamHandler.__init__(self)
|
||||
self.message_key = message_key
|
||||
|
||||
def format(self, record):
|
||||
|
@ -177,7 +178,7 @@ class TTYHandler(log.StreamHandler):
|
|||
msg = record.getMessage()
|
||||
if self.supports_color():
|
||||
level = ''
|
||||
if self.level <= log.DEBUG:
|
||||
if self.level <= logging.DEBUG:
|
||||
# add level name before message
|
||||
level = '%s ' % record.levelname
|
||||
elif record.levelname in ['SUCCESS', 'WARNING', 'ERROR']:
|
||||
|
@ -194,11 +195,11 @@ class TTYHandler(log.StreamHandler):
|
|||
|
||||
def emit(self, record):
|
||||
# set proper stream first
|
||||
if record.levelno >= log.WARNING:
|
||||
if record.levelno >= logging.WARNING:
|
||||
self.stream = sys.stderr
|
||||
else:
|
||||
self.stream = sys.stdout
|
||||
log.StreamHandler.emit(self, record)
|
||||
logging.StreamHandler.emit(self, record)
|
||||
|
||||
def supports_color(self):
|
||||
"""Check whether current stream supports color."""
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
import logging
|
||||
from logging import addLevelName, setLoggerClass, Logger, getLogger, StreamHandler
|
||||
from logging import addLevelName, setLoggerClass, Logger, getLogger
|
||||
|
||||
|
||||
# Global configuration and functions -----------------------------------
|
||||
|
|
Loading…
Reference in a new issue