AndyC
AndyC

Reputation: 2543

Python Flask - tracking a request for logging purposes

I'm not sure if I'm missing something obvious here as this appears like it would be a common issue.

I setup basic python logging to allow me add some debug during various parts of my Flask web service, but I realised if more than one request comes in at one time I won't know which request the logging pertains to.

How can I uniquely 'tag' each request that comes in, and modify the default logging format to include this tag?

Upvotes: 2

Views: 2909

Answers (1)

Vinay Sajip
Vinay Sajip

Reputation: 99297

Here's a post about doing this sort of logging for web applications in general; the approach should work with Flask in particular (the post was written for Armin Ronacher).

tl; dr: Use thread-locals.

Upvotes: 4

Related Questions