| |
@@ -1,21 +1,20 @@
|
| |
# SPDX-License-Identifier: GPL-2.0+
|
| |
|
| |
import logging
|
| |
- import sys
|
| |
|
| |
|
| |
- def log_to_stdout(level=logging.INFO):
|
| |
- fmt = '%(asctime)s [pid %(process)5d] %(name)s %(levelname)s %(message)s'
|
| |
- datefmt = '%Y-%m-%d %H:%M:%S'
|
| |
- stream_handler = logging.StreamHandler(sys.stdout)
|
| |
- stream_handler.setLevel(level)
|
| |
- stream_handler.setFormatter(logging.Formatter(fmt=fmt, datefmt=datefmt))
|
| |
- logging.getLogger().addHandler(stream_handler)
|
| |
+ def log_to_gunicorn(app):
|
| |
+ gunicorn_logger = logging.getLogger('gunicorn.error')
|
| |
+ # Wire up the root logger to forward to gunicorn's handlers
|
| |
+ logging.getLogger().handlers = gunicorn_logger.handlers
|
| |
+ logging.getLogger().setLevel(gunicorn_logger.level)
|
| |
+ # Wire up the flask logger to forward to gunicorn's handlers
|
| |
+ app.logger.handlers = gunicorn_logger.handlers
|
| |
+ app.logger.setLevel(gunicorn_logger.level)
|
| |
|
| |
|
| |
def init_logging(app):
|
| |
- log_level = logging.DEBUG if app.debug else logging.INFO
|
| |
- log_to_stdout(level=log_level)
|
| |
+ log_to_gunicorn(app)
|
| |
# In general we want to see everything from our own code,
|
| |
# but not detailed debug messages from third-party libraries.
|
| |
# Note that the log level on the handler above controls what
|
| |
Gunicorn has been swallowing all of our log output in openshift making it
impossible to know what's going on. Tested locally, this gets us output to
stdout from both the flask app and the root logger.