[fix] don't circumway logging module

This commit is contained in:
Laurent Peuch 2016-12-22 13:26:11 +01:00
parent f41eb29953
commit 23276c6941
3 changed files with 18 additions and 16 deletions

View file

@ -3,6 +3,7 @@
import os import os
import re import re
import errno import errno
import logging
import argparse import argparse
from json import dumps as json_encode from json import dumps as json_encode
@ -30,14 +31,14 @@ class LogQueues(dict):
pass pass
class APIQueueHandler(log.Handler): class APIQueueHandler(logging.Handler):
""" """
A handler class which store logging records into a queue, to be used A handler class which store logging records into a queue, to be used
and retrieved from the API. and retrieved from the API.
""" """
def __init__(self): def __init__(self):
log.Handler.__init__(self) logging.Handler.__init__(self)
self.queues = LogQueues() self.queues = LogQueues()
def emit(self, record): def emit(self, record):
@ -673,7 +674,7 @@ class Interface(BaseInterface):
# Attempt to retrieve log queues from an APIQueueHandler # Attempt to retrieve log queues from an APIQueueHandler
if log_queues is None: if log_queues is None:
handler = log.getHandlersByClass(APIQueueHandler, limit=1) handler = logging.getHandlersByClass(APIQueueHandler, limit=1)
if handler: if handler:
log_queues = handler.queues log_queues = handler.queues

View file

@ -5,6 +5,7 @@ import sys
import errno import errno
import getpass import getpass
import locale import locale
import logging
from argparse import SUPPRESS from argparse import SUPPRESS
from collections import OrderedDict from collections import OrderedDict
@ -142,7 +143,7 @@ def get_locale():
# CLI Classes Implementation ------------------------------------------- # CLI Classes Implementation -------------------------------------------
class TTYHandler(log.StreamHandler): class TTYHandler(logging.StreamHandler):
"""TTY log handler """TTY log handler
A handler class which prints logging records for a tty. The record is A handler class which prints logging records for a tty. The record is
@ -159,17 +160,17 @@ class TTYHandler(log.StreamHandler):
""" """
LEVELS_COLOR = { LEVELS_COLOR = {
log.NOTSET: 'white', logging.NOTSET: 'white',
log.DEBUG: 'white', logging.DEBUG: 'white',
log.INFO: 'cyan', logging.INFO: 'cyan',
log.SUCCESS: 'green', logging.SUCCESS: 'green',
log.WARNING: 'yellow', logging.WARNING: 'yellow',
log.ERROR: 'red', logging.ERROR: 'red',
log.CRITICAL: 'red', logging.CRITICAL: 'red',
} }
def __init__(self, message_key='fmessage'): def __init__(self, message_key='fmessage'):
log.StreamHandler.__init__(self) logging.StreamHandler.__init__(self)
self.message_key = message_key self.message_key = message_key
def format(self, record): def format(self, record):
@ -177,7 +178,7 @@ class TTYHandler(log.StreamHandler):
msg = record.getMessage() msg = record.getMessage()
if self.supports_color(): if self.supports_color():
level = '' level = ''
if self.level <= log.DEBUG: if self.level <= logging.DEBUG:
# add level name before message # add level name before message
level = '%s ' % record.levelname level = '%s ' % record.levelname
elif record.levelname in ['SUCCESS', 'WARNING', 'ERROR']: elif record.levelname in ['SUCCESS', 'WARNING', 'ERROR']:
@ -194,11 +195,11 @@ class TTYHandler(log.StreamHandler):
def emit(self, record): def emit(self, record):
# set proper stream first # set proper stream first
if record.levelno >= log.WARNING: if record.levelno >= logging.WARNING:
self.stream = sys.stderr self.stream = sys.stderr
else: else:
self.stream = sys.stdout self.stream = sys.stdout
log.StreamHandler.emit(self, record) logging.StreamHandler.emit(self, record)
def supports_color(self): def supports_color(self):
"""Check whether current stream supports color.""" """Check whether current stream supports color."""

View file

@ -1,6 +1,6 @@
import os import os
import logging import logging
from logging import addLevelName, setLoggerClass, Logger, getLogger, StreamHandler from logging import addLevelName, setLoggerClass, Logger, getLogger
# Global configuration and functions ----------------------------------- # Global configuration and functions -----------------------------------