Easy to use logging for Stockholm University.
For normal usage which logs to syslog:
from su.logging import logging
logger = logging.getLogger("myapp")
logger.warning("My WARNING message")
For easier developing you can also switch to console logging:
from su.logging import console, logging
logger = logging.getLogger("myapp")
logger.warning("My WARNING message")
We use
logstash_formatter's
LogstashFormatterV1
and remove some unused/unnecesary fields.
Depend on su-logging[structured]
in e.g. your requirements.txt
and then:
from su.logging import logging, structured
logger = logging.getLogger("myapp")
logger.warning("User logged in", extra={"user": "simlu"})
try:
raise Exception("User performed illegal activity")
except Exception as e:
logger.exception(e, extra={"user": "simlu"})
In Containers, which usually adhere to the 12 factor apps manifesto, you usually log to STDOUT and let your container engine deal with them.
from su.logging import console, logging, structured
logger = logging.getLogger("myapp")
logger.warning("My WARNING message")