title: Python logging in multiprocessing: AttributeError: 'Logger' object has no attribute 'flush'
body: <p>Based on this <a href="https://stackoverflow.com/a/5916874">code</a> I created a python object that both prints output to the terminal and saves the output to a log file with the date and time appended to its name:</p>
  
  <pre><code>import sys
  import time
  
  class Logger(object):
      """
      Creates a class that will both print and log any
      output text. See https://stackoverflow.com/a/5916874
      for original source code. Modified to add date and
      time to end of file name.
      """
      def __init__(self, filename="Default"):
          self.terminal = sys.stdout
          self.filename = filename + ' ' + time.strftime('%Y-%m-%d-%H-%M-%S') + '.txt'
          self.log = open(self.filename, "a")
  
      def write(self, message):
          self.terminal.write(message)
          self.log.write(message)
  
  
  sys.stdout = Logger('TestLog')
  </code></pre>
  
  <p>This works great, but when I try to use it with a script that uses the <code>Pool</code> multiprocessing function, I get the following error:</p>
  
  <pre><code>AttributeError: 'Logger' object has no attribute 'flush'
  </code></pre>
  
  <p>How can I modify my <code>Logger</code> object so that it will work with any script that runs in parallel?</p>