Release 8f7c85c45e72c364342dcebaf79cd1d2

This commit is contained in:
Dirk Alders 2020-12-21 01:20:59 +01:00
parent ce174339bc
commit 25889f225b
3 changed files with 2188 additions and 2160 deletions

View File

@ -29,13 +29,17 @@ report (Report Module)
__DEPENDENCIES__ = []
import collections
import json
import logging
from logging.config import dictConfig
import os
import sys
logger_name = 'REPORT'
logger = logging.getLogger(logger_name)
try:
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.
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[-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', ]
if basepath is not None:
target_handlers.append('logwarn')
# define handler
#
if target == 'stdout':
@ -167,7 +179,7 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
elif target == 'logfile':
handler = dict(main={
'level': 'DEBUG',
'formatter': 'format',
'formatter': 'json',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(basepath, 'messages.log'),
'mode': 'a',
@ -180,22 +192,20 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
'formatter': 'my_format',
'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:
target_handlers.append('ring')
handler['ring'] = {
'class': 'report.collectingRingHandler',
'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
#
loggers = {}
@ -210,6 +220,9 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
dictConfig(dict(
version=1,
formatters={
'json': {
'()': JsonFormatter
},
'long': {
'format': LONG_FMT
},

File diff suppressed because it is too large Load Diff

Binary file not shown.