GlennS
GlennS

Reputation: 5601

How can I get UWSGI to log Flask log messages at the correct level?

I have a uwsgi service running under systemd. It appears to be logging everything it received from its hosted Flask application as INFO level, rather than whatever level it was supposed to be logged under.

In my Python code, I have a Flask application called app. I call:

app.logger.error('TESTING LOGGING')

When I check my logs using journalctl -u uwsgi -p err, I don't see the message I logged. When I use journalctl -u uwsgi -p info, I do.

I'm not using the systemd_logger plugin for uwsgi, but it doesn't look like it would fix this problem, because it also always logs at INFO level: https://github.com/unbit/uwsgi/blob/3149df02ed443131c54ea6afb29fcbb0ed4d1139/plugins/systemd_logger/systemd_logger.c#L13

Upvotes: 1

Views: 1656

Answers (1)

GlennS
GlennS

Reputation: 5601

UWSGI won't log these messages to the right level, but I was able to do it directly from within Flask, by using the Python systemd package.

import logging
from systemd import journal

logger = logging.getLogger(__name__)
journaldHandler = journal.JournalHandler()
logger.addHandler(journaldHandler)

logger.error('TESTING LOGGING')

https://pypi.org/project/systemd/

Upvotes: 1

Related Questions