supervisord logging tornado errors twice in the stdout

我的未来我决定 提交于 2019-12-08 10:56:17

问题


My supervisord config is the following

[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
logfile_maxbytes=0        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
user=root
group=root

[program:tornado]
command=python3 tornadoaas.py
directory=/tornado_api
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
loglevel=info
redirect_stderr=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
user=root
group=root

so I'm sending tornado logs to stdout and stderr, while I have set supervisord process logging to /dev/null to avoid it to write to the console - see here.

When in production I set the logging level to ERROR. What happens when using logging.error I get the error logs twice in the console.

This is my python logger configuration

def configure_logger(self, name='default'):
        """ configure a logger """
        dictConfig({
            'version': 1,
            'formatters': {
                'default': {'format': '%(asctime)s - %(levelname)s - %(message)s', 'datefmt': '%Y-%m-%d %H:%M:%S'}
            },
            'handlers': {
                'console': {
                    'level': log_level,
                    'class': 'logging.StreamHandler',
                    'formatter': 'default',
                    'stream': 'ext://sys.stdout'
                }
            },
            'loggers': {
                'default': {
                    'level': log_level,
                    #'handlers': ['console', 'file']
                    'handlers': ['console']
                }
            },
            'disable_existing_loggers': False
        })

        # disable logging propagation to stderr
        hn = logging.NullHandler()
        hn.setLevel( log_level )
        logging.getLogger("tornado.general").addHandler(hn)
        logging.getLogger("tornado.application").addHandler(hn)
        logging.getLogger("tornado.access").addHandler(hn)
        logging.getLogger("tornado.general").propagate = False
        logging.getLogger("tornado.application").propagate = False
        logging.getLogger("tornado.access").propagate = False

        logger = logging.getLogger(name) 
        return logger 

where

log_level = logging.DEBUG if DIST == 'dev' else logging.ERROR

来源:https://stackoverflow.com/questions/56875104/supervisord-logging-tornado-errors-twice-in-the-stdout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!