简体   繁体   中英

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. 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 . Use a method like the one described in the logging cookbook to handle this case - only one process should be writing to the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM