Consider a multi threaded python application using python logger module. I want to do per thread logging, so I have appended the a unique-ID (not thread id) at the bottom of
Although, I am not really experienced in what I am suggesting, I would try to use Thread-local storage.
Thread-local storage
A class that represents thread-local data. Thread-local data are data whose values are thread specific. To manage thread-local data, just create an instance of local (or a subclass) and store attributes on it. The instance’s values will be different for separate threads.
You can then save and access the variables in the following way:
import threading
mydata = threading.local()
mydata.x = 1
I suggest to save the thread-specific logger to the thread-local variable when you create it and then access the logger again when necessary through the thread-local storage.
Have a look, it helped me to understand thread-local: