I have three classes in python and they run in different threads. I would like to have output to the same file from all classes. Right now I created output method in main class and passing it through constructors to other classes. Is there way to handle it better? How I can pass the logger between classes except using contructors?
Perhaps python supports something like static method in Java, so I can write like Logger.info(message) in all three classes?
Another way probably could be redirecting global sys.stdout to the file, i.e specifying
logger = open('debug.txt', 'w')
sys.stdout = logger
Then using calls sys.stdout in all classes.
What do you think?
And get in debug.txt:
Note that the order in which the messages appear in the log file may not correspond exactly to the order in which they happened when you're logging from several threads.