[Python] Getting username from flask session into gunicorn log

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a way to include a value from the flask session (like username in this case) into the access log of gunicorn?

    I know that I can include custom values with a filter like this:

    class UserFilter(logging.Filter):
    def filter(self, record):
    record.username = "TestUser"
    return True


    But as soon as I try to get the value for record.username from the session I get:


    RuntimeError: Working outside of request context.

    This typically means that you attempted to use functionality that needed an active HTTP request. Consult the documentation on testing for information about how to avoid this problem.
    ​

    Continue reading...

Compartilhe esta Página