title: Logging level randomly changing and not always writing to file
body: <p>I have this piece of code to set my logger in Python:</p>
  
  <pre><code>  #Configure logging
    logging.basicConfig(format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                        datefmt='%m-%d %H:%M',
                        filename= "log.txt",
                        level = logging.getLevelName('DEBUG'))
  
  
    print(logging.getLogger().getEffectiveLevel())
  </code></pre>
  
  <p>But the output from the print statement sometimes is this:</p>
  
  <pre><code>30
  </code></pre>
  
  <p>And other times is this (which is correct):</p>
  
  <pre><code>10
  </code></pre>
  
  <p>But often even when the the logging level is set to the correct number, it is not logging anything to the file, but other times it works. What do I need to do to make sure my logging level is set correctly?</p>
  
  <p>*Edit: Below is my solution based off the recommendation of @randomir.
  **Edit: I had to make a second change where I set the level after I call <code>logging.basicConfig()</code> or else the logging level still was not getting called consistently. The line `logging.getLogger().setLevel(...) now seems to work.  </p>
  
  <p>I created a new class: Logger.py.     </p>
  
  <pre><code>import logging
  
  class Logger(object):
     def __init__(self):
       logging.basicConfig(format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                        datefmt='%m-%d %H:%M',
                        filename= "log.txt")
  
       logging.getLogger().setLevel(logging.getLevelName("DEBUG"))
  
       print(logging.getLogger().getEffectiveLevel())
  </code></pre>
  
  <p>And now instead of configuring the basic config directly in my startup class I just instantiate the logger class once:</p>
  
  <pre><code>from Logger import Logger
  import logging
  
  class LaunchPython(object):
    #Configure Logging
    Logger()
  
    logging.info("Application has started")
  </code></pre>
  
  <p>On all subsequent classes that call the logger I just put <code>import logging</code> on the top and then do <code>logging.info(...)</code> or <code>logging.debug(....)</code>. There is no need to import the Logger.py class and reinstantiate it.</p>