![](/img/trans.png)
[英]Why is Flask application not creating any logs when hosted by Gunicorn?
[英]Why writing logs on multiple files at the same time when using log rotation in my flask application running on gunicorn?
我在 gunicorn 上運行我的 Flask Web 應用程序並使用RotatingFileHandler
進行日志記錄。 我發現我的應用程序正在訪問多個日志文件,包括要記錄的后備文件,我可以觀察到日志目錄中所有文件的大小越來越大。
我不知道為什么會這樣。
您是否有類似的經歷或對這個問題有什么想法? 當大小未達到最大大小時旋轉文件。
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
不支持從多個進程寫入同一個文件,但乍一看似乎可行。 這就是gunicorn
的情況。 使用類似於日志記錄手冊中描述的方法來處理這種情況 - 只有一個進程應該寫入文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.