Python自定义日志记录

2024-04-23 21:38:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个webapp(Flask),我需要启用一些日志记录。我需要使用以下列登录到mysql表:

id, timestamp, userid, orderid, service, msg, response

我想使用python的std日志。 示例用法如下:

special_logger = logging.getSpecialLogger() # instead of logging.getLogger()

special_logger.setLevel(level=logging.DEBUG)
special_logger.addHandler(myMysqlHandler)
special_logger.debug(current_uid, myorderid, 'SERVICE1', 'Exception happened', serviceResponse)

我怎样才能做到?你知道吗


Tags: idflaskresponseloggingservice记录mysqlmsg
1条回答
网友
1楼 · 发布于 2024-04-23 21:38:52

只需使用一个普通的记录器和一个数据库处理程序,如this answer中所述。尽管我的另一个答案并没有特别针对MySQL,但它使用DB-API,因此应该适用于符合DB-API 2.0的MySQL Python驱动程序。你知道吗

更新:您可以按照文档here将额外数据传递到日志。你知道吗

相关问题 更多 >