2

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

You should mention that the blogpost you linked was not written by Armin, you're just referring to a post by Armin. Also, just linking to a blogpost isn't actually a valid answer on stackoverflow. At least copy an example in here.
I said it was written for Armin, so how could I be implying it was written by him? I'm not just referring to something Armin wrote, I provided an answer for this same question, which he posed. It's too long to post a simple example here, hence the link and tl;dr.
It is a long post and a little more complex than I needed, but the principals behind it are applicable for my needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.