[Flask] insert current_user value into logger generated emails?

Corey Boyle coreybrett at gmail.com
Sun Jul 4 11:51:35 EDT 2021


https://stackoverflow.com/questions/68246462/how-could-the-value-of-current-user-be-inserted-into-error-logs-emails-when-usin


On Sun, Jul 4, 2021 at 11:39 AM Felix Ramirez
<felixramirezreyes at gmail.com> wrote:
>
> Hi everyone,
> I'm interested in the Corey Boyle question too because I'm struggling with the same situations to add the current_user to logger but without success and the link that Can Hosgor doesn't answer her question but it's very interesting.
> I would appreciate any help with this.
>
> Thanks in advance to all.
>
>
> El vie, 2 de jul. de 2021 a la(s) 15:05, Can Hosgor (canhosgor at gmail.com) escribió:
>>
>> 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
>>
>> _______________________________________________
>> Flask mailing list
>> Flask at python.org
>> https://mail.python.org/mailman/listinfo/flask
>
>
>
> --
> Felix Ramirez R.


More information about the Flask mailing list