title: Logging in classes - Python
body: <p>I'm trying to use Python's <code>logging</code> module, and have questions on the best way to use it. </p>
  
  <p>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 :</p>
  
  <ul>
  <li>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 ?</li>
  <li>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 ? <a href="https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/" rel="noreferrer">This tutorial</a> told me not to, but I don't really get why.</li>
  </ul>
  
  <p>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.</p>
  
  <p>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 ?</p>