title: How can I suppress stdout logging output for a module I'm importing?
body: <p>I'm importing a module <code>foo</code> which uses Python's <code>logging</code> module. However, <code>foo</code> produces a huge amount of logging output, and I need to use <code>stdout</code> to communicate important information to the user, which is largely being drowned out by the ridiculous output of the module I'm importing.</p>
  
  <p>How can I disable the module's ability to log to <code>stdout</code> without modifying <code>foo</code>'s code? I still want it to log to the files it logs to, but I don't want it logging to <code>stdout</code>.</p>
  
  <p>I have tried the following:</p>
  
  <p><code>logging.getLogger("foo").propagate = False</code></p>
  
  <p>and</p>
  
  <pre><code>@contextlib.contextmanager
  def nostdout():
      class DummyFile(object):
          def write(self, x): pass
      save_stdout = sys.stdout
      sys.stdout = DummyFile()
      yield
      sys.stdout = save_stdout
  
  with nostdout(): import foo
  </code></pre>