Release 8f7c85c45e72c364342dcebaf79cd1d2
This commit is contained in:
parent
ce174339bc
commit
25889f225b
45
__init__.py
45
__init__.py
@ -29,13 +29,17 @@ report (Report Module)
|
|||||||
__DEPENDENCIES__ = []
|
__DEPENDENCIES__ = []
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
from logging.config import dictConfig
|
from logging.config import dictConfig
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
logger_name = 'REPORT'
|
try:
|
||||||
logger = logging.getLogger(logger_name)
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
||||||
|
except ImportError:
|
||||||
|
ROOT_LOGGER_NAME = 'root'
|
||||||
|
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
||||||
|
|
||||||
__DESCRIPTION__ = """The Module {\\tt %s} is designed to help with python logging and to support some handlers for logging to memory.
|
__DESCRIPTION__ = """The Module {\\tt %s} is designed to help with python logging and to support some handlers for logging to memory.
|
||||||
For more Information read the sphinx documentation.""" % __name__.replace('_', '\_')
|
For more Information read the sphinx documentation.""" % __name__.replace('_', '\_')
|
||||||
@ -151,10 +155,18 @@ class collectingTestcaseHandler(collectingHandler):
|
|||||||
self.MY_LOGS.append(record.__dict__)
|
self.MY_LOGS.append(record.__dict__)
|
||||||
self.MY_LOGS[-1]['moduleLogger'] = collectingHandler().get_logs()
|
self.MY_LOGS[-1]['moduleLogger'] = collectingHandler().get_logs()
|
||||||
|
|
||||||
def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_logs=None):
|
|
||||||
|
class JsonFormatter(logging.Formatter):
|
||||||
|
def format(self, record):
|
||||||
|
obj = {}
|
||||||
|
for key in ["name", "levelno", "levelname", "pathname", "filename", "module", "lineno", "funcName", "created", "msecs", "relativeCreated", "thread", "threadName", "process", "processName", "msg", "args", "exc_info", "exc_text"]:
|
||||||
|
obj[key] = getattr(record, key)
|
||||||
|
obj["msg"] = obj["msg"] % obj["args"]
|
||||||
|
return json.dumps(obj)
|
||||||
|
|
||||||
|
|
||||||
|
def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_logs=None, host=None, port=None):
|
||||||
target_handlers = ['main', ]
|
target_handlers = ['main', ]
|
||||||
if basepath is not None:
|
|
||||||
target_handlers.append('logwarn')
|
|
||||||
# define handler
|
# define handler
|
||||||
#
|
#
|
||||||
if target == 'stdout':
|
if target == 'stdout':
|
||||||
@ -167,7 +179,7 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
|
|||||||
elif target == 'logfile':
|
elif target == 'logfile':
|
||||||
handler = dict(main={
|
handler = dict(main={
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'formatter': 'format',
|
'formatter': 'json',
|
||||||
'class': 'logging.handlers.RotatingFileHandler',
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
'filename': os.path.join(basepath, 'messages.log'),
|
'filename': os.path.join(basepath, 'messages.log'),
|
||||||
'mode': 'a',
|
'mode': 'a',
|
||||||
@ -180,22 +192,20 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
|
|||||||
'formatter': 'my_format',
|
'formatter': 'my_format',
|
||||||
'class': 'logging.NullHandler',
|
'class': 'logging.NullHandler',
|
||||||
})
|
})
|
||||||
|
if host is not None and port is not None:
|
||||||
|
target_handlers.append('socket')
|
||||||
|
handler['socket']={
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.handlers.SocketHandler',
|
||||||
|
'host': host,
|
||||||
|
'port': port
|
||||||
|
}
|
||||||
if ring_logs is not None:
|
if ring_logs is not None:
|
||||||
target_handlers.append('ring')
|
target_handlers.append('ring')
|
||||||
handler['ring'] = {
|
handler['ring'] = {
|
||||||
'class': 'report.collectingRingHandler',
|
'class': 'report.collectingRingHandler',
|
||||||
'max_logs': ring_logs,
|
'max_logs': ring_logs,
|
||||||
}
|
}
|
||||||
if basepath is not None:
|
|
||||||
handler['logwarn'] = {
|
|
||||||
'level': 'WARNING',
|
|
||||||
'formatter': 'long',
|
|
||||||
'class': 'logging.handlers.RotatingFileHandler',
|
|
||||||
'filename': os.path.join(basepath, 'messages.warn'),
|
|
||||||
'mode': 'a',
|
|
||||||
'maxBytes': 10485760,
|
|
||||||
'backupCount': 2
|
|
||||||
}
|
|
||||||
# define loggers
|
# define loggers
|
||||||
#
|
#
|
||||||
loggers = {}
|
loggers = {}
|
||||||
@ -210,6 +220,9 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
|
|||||||
dictConfig(dict(
|
dictConfig(dict(
|
||||||
version=1,
|
version=1,
|
||||||
formatters={
|
formatters={
|
||||||
|
'json': {
|
||||||
|
'()': JsonFormatter
|
||||||
|
},
|
||||||
'long': {
|
'long': {
|
||||||
'format': LONG_FMT
|
'format': LONG_FMT
|
||||||
},
|
},
|
||||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user