1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-04-03 00:07:05 +00:00

hook python's log to gunicorn's

This commit is contained in:
downtownallday 2022-09-19 14:47:50 -04:00
parent bf63ca827e
commit 76e7528b34

View File

@ -102,19 +102,21 @@ def add_python_logging(app):
if app.debug:
log_level = logging.DEBUG
log_handler = logging.StreamHandler()
logging.basicConfig(level=log_level, handlers=[])
log_handler.setLevel(log_level)
log_handler.addFilter(AuthLogFilter(
app.debug,
get_session_username
))
log_handler.setFormatter(AuthLogFormatter())
log = logging.getLogger('')
log.addHandler(log_handler)
# log to syslog in production mode
# hook python log to gunicorn in production mode
else:
import utils
log_level = logging.INFO
log_handler = utils.create_syslog_handler()
gunicorn_logger = logging.getLogger('gunicorn.error')
log = logging.getLogger('')
log.handlers = gunicorn_logger.handlers
log.setLevel(gunicorn_logger.level)
logging.basicConfig(level=log_level, handlers=[])
log_handler.setLevel(log_level)
log_handler.addFilter(AuthLogFilter(
app.debug,
get_session_username
))
log_handler.setFormatter(AuthLogFormatter())
log = logging.getLogger('')
log.addHandler(log_handler)