python日志记录到数据库 [英] python logging to database

查看:472
本文介绍了python日志记录到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法让python记录器模块记录到数据库,并在数据库关闭时回到文件系统。

I'm seeking a way to let the python logger module to log to database and falls back to file system when the db is down.

:如何让记录器记录到数据库,以及如何在数据库关闭时将其记录到文件记录中。

So basically 2 things: How to let the logger log to database and how to make it fall to file logging when the db is down.

推荐答案

自己将日志导向数据库的 处理程序 问题。当它失败时,您可以从记录器的处理程序列表中删除它。有许多方法来处理故障模式。

Write yourself a handler that directs the logs to the database in question. When it fails, you can remove it from the handler list of the logger. There are many ways to deal with the failure-modes.

这篇关于python日志记录到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆