使用Flask和RotatingFileHandler进行原子日志文件旋转 [英] Atomic log file rotation with Flask and RotatingFileHandler

查看:110
本文介绍了使用Flask和RotatingFileHandler进行原子日志文件旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Flask应用程序中使用标准的 RotatingFileHandler 和下一个参数: maxBytes = 10 * 1024 * 1024,backupCount = 50 .应用由nginx后面的uWSGI管理.uWSGI配置文件部分如下所示:

I use standard RotatingFileHandler within my Flask application with next parameters: maxBytes=10 * 1024 * 1024, backupCount=50. App is managed by uWSGI behind nginx. uWSGI config file part looks like this:

processes = 16
enable-threads = true
threads = 10

启动应用后,一切(我的意思是记录)运行良好.但是,在第一次轮换日志文件之后,某些进程(也许还有线程)继续写入轮换的文件,而有些则写入新文件.这很明显.但是对我来说,如何以所有进程(和线程)开始将消息写入新文件的方式旋转日志文件并不是很明显.

Right after start of an app everything (I mean logging) works well. But after first log file rotation some processes (and maybe threads too) continue writing to rotated file and some - to new one. It is obvious. But for me it is not so obvious how can I rotate log file in the way that all of my processes (and threads) start to write messages to new file.

推荐答案

请注意,不支持从多个进程写入单个日志文件,因为没有可以使用的跨平台同步机制.请参见本食谱条目以获取可能适合您的建议方法.

Note that writing to a single log file from multiple processes isn't supported, because there is no cross-platform synchronisation mechanism that can be used. See this cookbook entry for a suggested approach which might work for you.

这篇关于使用Flask和RotatingFileHandler进行原子日志文件旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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