I'm trying to use Python's logging
module, and have questions on the best way to use it.
I define several classes, want to write logs and be able to set the level of all of them at the same time. I tried :
- to use the same logger everywhere. But my classes are used by a framework, I don't have a single entrypoint where I could define a main logger. If so, how should I create it and add handlers ?
- to use one logger per file. Should I create it as a class attribute, and adding handlers only the first time the class is instantiated ? Or put it with the imports before the class definition ? This tutorial told me not to, but I don't really get why.
Thanks for any hints. I've found lots of docs on the basic way to use a logger, but not much on how to use it in classes.
EDIT: I don't think it's a duplicate of the link below. The accepted answer explains how to load the config in a main program, and then use it in all the modules. But what if I don't have a main program ? Where do I define it ?