我的python Flask应用程序中有一个自定义格式化程序,我已将其添加到根记录器中:
logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
formatter = CustomLoggingFormatter()
handler.setFormatter(formatter)
logger.addHandler(handler)
以下是日志消息的示例:
“*在%s上运行://%s:%d/%s”}
我认为我的格式化程序可能有问题,但当我记录CustomLoggingFormatter接收到的日志记录时,上面一行看起来是这样的:
日志记录:werkzeug,20,<&燃气轮机/lib/python3.5/site-packages/werkzeug/_内部。py,87,“*在%s上运行://%s:%d/%s”
class CustomLoggingFormatter(Formatter):
data = {}
def __init__(self):
super(CustomLoggingFormatter, self).__init__()
def format(self, record):
print(record)
input_data = {}
input_data['@timestamp'] = datetime.utcnow().isoformat()[:-3] + 'Z'
input_data['level'] = record.levelname
if record.msg:
input_data['message'] = record.msg
input_data.update(self.data)
return json.dumps(input_data)