title: How to use doctest with logging?
body: <p>The following doctest fails:</p>
  
  <pre><code>import logging
  logging.basicConfig(level=logging.DEBUG,format='%(message)s')
  
  def say_hello():
    '''
    &gt;&gt;&gt; say_hello()
    Hello!
    '''
    logging.info('Hello!')
  
  if __name__ == '__main__':
      import doctest
      doctest.testmod()
  </code></pre>
  
  <p>These pages</p>
  
  <ul>
  <li><a href="http://www.daniweb.com/software-development/python/threads/142823/doctest-logging" rel="noreferrer">doctest &amp; logging</a>  </li>
  <li><a href="https://stackoverflow.com/q/2717834/341970">use doctest and logging in python program</a></li>
  </ul>
  
  <p>seem to suggest <code>logging.StreamHandler(sys.stdout)</code> and <code>logger.addHandler(handler)</code> but my attempts failed in this respect. (I am new to python, if it wasn't obvious .)</p>
  
  <p>Please help me fix the above code so that the test passes.</p>
  
  <hr>
  
  <p><strong>Update on Jun 4, 2017:</strong> To answer <a href="https://stackoverflow.com/users/1998076/00prometheus">00prometheus</a>' comments: The accepted answer to <a href="https://stackoverflow.com/q/2717834/341970">use doctest and logging in python program</a>, when I asked this question, seemed unnecessarily complicated. And indeed it is, as the accepted answer here gives a simpler solution. In my highly biased opinion, my question is also clearer than the one I already linked in the original post.</p>