Logging ======= We use ``structlog`` to format the logs generated by the application. We redirect the logs to STDOUT as JSON. You need to use an external system to collect an aggregate the logs. Lego contains a middleware that binds request information to each log message. There is no need to add things like request path and authenticated user to the log message, this is done automatically. Import and use the logger ------------------------- :: from structlog import get_logger log = get_logger() log.warn('important_message', message_recipient=user.username) Celery and structlog -------------------- If you also want to add the request context to log messages in celery tasks you have to use a special task base and bind the task. Also remember to call the ``setup_logger`` function. :: @celery_app.task(bind=True, base=AbakusTask) def task_name(self, normal_argument, logger_context=None): self.setup_logger(logger_context) other work... .. automodule:: lego.utils.tasks :members: AbakusTask :show-inheritance: