[Flask] insert current_user value into logger generated emails?

Can Hosgor canhosgor at gmail.com
Fri Jul 2 15:05:08 EDT 2021


You can try writing a custom logging Filter that gets current user from the
request context and puts it into the log record. Then it will be available
for the log formatter. Check out the example here
https://stackoverflow.com/a/17558764


On Thu, 1 Jul 2021 at 15:55 Corey Boyle <coreybrett at gmail.com> wrote:

> I have the following code in my app factory...
>
>     mh = SMTPHandler(
>         mailhost=app.config["MAIL_SERVER"],
>         fromaddr=app.config["MAIL_DEFAULT_SENDER"],
>         toaddrs=app.config["ERRORS_EMAIL"],
>         subject="Error",
>     )
>     mh.setLevel(logging.ERROR)
>     app.logger.addHandler(mh)
>
> Is there any way to get the value of "current_user" inserted into the
> email somewhere?
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/flask/attachments/20210702/16695ca1/attachment.html>


More information about the Flask mailing list