问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/28021282/atomic-log-file-rotation-with-flask-and-rotatingfilehandler