Why Flask logger does not log in docker when using UWSGI in front?

后端 未结 2 1006

I have a Flask application inside of Docker that was logging into docker logs when it was running without UWSGI in front. Now

2条回答
  •  遥遥无期
    2021-02-07 07:34

    I had a similar problem (Special: I wanted to use the syslog). First I had to add a rule to the Dockerfile:

    RUN apt-get install -y rsyslog
    service rsyslog start
    

    Flask comes with build-in logging, so I just had to add some twigs

    from flask import Flask
    import logging
    import logging.handlers
    
    handler = logging.handlers.SysLogHandler(address = '/dev/log')
    handler.setFormatter(logging.Formatter('flask [%(levelname)s] %(message)s'))
    
    app = Flask(__name__)
    app.logger.addHandler(handler)
    

    Additional settings can be handled through the syslog-daemon

提交回复
热议问题