[英]Why writing logs on multiple files at the same time when using log rotation in my flask application running on gunicorn?
I am running my flask web application on gunicorn and using RotatingFileHandler
for logging.我在 gunicorn 上运行我的 Flask Web 应用程序并使用
RotatingFileHandler
进行日志记录。 I found my app was accessing multiple logging files including back files to log and I could observe sizes of all files in a logging directory was getting bigger.我发现我的应用程序正在访问多个日志文件,包括要记录的后备文件,我可以观察到日志目录中所有文件的大小越来越大。
I have no idea why this is happening.我不知道为什么会这样。
Do you have similar experiences or have any thoughts on this issue?您是否有类似的经历或对这个问题有什么想法? And a file rotated when size didn't reach max size.
当大小未达到最大大小时旋转文件。
number of gunicorn workers = 9
logging_config = dict(
disable_existing_loggers=False,
formatters={
'simple_formatter': {'format': '%(message)s'}
},
handlers={
'file_handler': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'simple_formatter',
'filename': 'applog.log',
'maxBytes': 10 * 1024 * 1024,
'backupCount': 10
},
},
root={
'handlers': ['file_handler'],
'level': logging.DEBUG,
}
)
-rw-rw-r-- 1 2.5M Sep 23 11:29 applog.log
-rw-rw-r-- 1 1.9M Sep 23 11:29 applog.log.1
-rw-rw-r-- 1 2.3M Sep 23 11:29 applog.log.2
-rw-rw-r-- 1 5.5M Sep 23 11:29 applog.log.3
-rw-rw-r-- 1 2.0M Sep 23 11:29 applog.log.4
-rw-rw-r-- 1 4.4M Sep 23 11:29 applog.log.5
-rw-rw-r-- 1 2.7M Sep 23 11:29 applog.log.6
-rw-rw-r-- 1 2.6M Sep 23 11:29 applog.log.7
-rw-rw-r-- 1 7.1M Sep 23 11:29 applog.log.8
-rw-rw-r-- 1 10M Sep 23 11:21 applog.log.9
Writing to the same file from multiple processes isn't supported, though it might seem to work at first glance.不支持从多个进程写入同一个文件,但乍一看似乎可行。 This would be the situation with
gunicorn
.这就是
gunicorn
的情况。 Use a method like the one described in the logging cookbook to handle this case - only one process should be writing to the file.使用类似于日志记录手册中描述的方法来处理这种情况 - 只有一个进程应该写入文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.