Is it possible to dynamically change log file location based on route in flask?

I have a flask app with various routes setup.

I want to log messages to go to a different log file for each route.

Is this possible?

In the function that responds to the request on each route I have tried doing something like this (note this is just pseudo-code for sake of example):

@app.route('/routeA', methods=['POST'])
def routeA():

@app.route('/routeB', methods=['POST'])
def routeB():

@app.route('/routeC', methods=['POST'])
def routeC():

Which I would hope means that requests to routeC go to RouteC.log and similar for A and B

BUT if after starting uwsgi I hit /routeC first this seems to set up all logs to got to routeC.log such that when I then hit routes A or B their log lines also end up in the routeC.log

Similar occurs if I hit routeB or routeA first - whichever gets the first request establishes logging to that file and the other routes don't seem to be able to override that for their requests.

Is this kind of dynamic setting log file location depending on request actually possible?

If so what am I doing wrong?

I feel like I'm missing something basic here...

Read more here:

Content Attribution

This content was originally published by CoderChris at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: