Logging in Dash

Viewed 3185

I have a Dash application and I am trying to get proper logging in place. So for that I am trying to implement that after every request my log handler captures the following things (please suggest best practices if I missed any):

  • Time
  • Type of the request method (Get/post)
  • The path requested
  • Request referrer
  • Request agent
  • Selected inputs and flags from the front end
  • Response status
  • Response content_length
  • If I can capture the time between the request and response

Is there a way to capture this? I tried looking but couldn't find out many things that I can log.

So far the code I have is the following -

@dash_server.after_request
def after_request(response):
    """ Logging after every request. """
    logger = logging.getLogger("app.access")
    logger.info("%s [%s] %s %s %s %s %s %s %s",
                dt.utcnow().strftime("%d/%b/%Y:%H:%M:%S.%f")[:-3],
                dash.callback_context.triggered,
                dash.callback_context.inputs,
                response.status,
                response.content_length)
    return response

I am not sure how to capture the rest and I couldn't find a guide to perform this action.

0 Answers
Related