title: How to save logging info (info, debug, warning, error and critical) into a text file - Python
body: <p>How can I save the logging info of my following code if the target file is "C:\test\Logging\logging.txt? The idea it's to keep writing as long the script is running.</p>
  
  <pre><code>import os
  from threading import Timer
  from os.path import isfile, join, exists
  import shutil, time
  
  PATH_TO_WATCH = "C:\\Test"
  
  class FileReader:
  
      def __init__(self, path = None):
          self.path = path
          self.running = False
          self.timer = None
  
      def printFilesData(self, files):
          if self.path:
              timestamp = time.strftime("%d-%m-%Y-%H-%M-%S")
              destination = join(self.path, timestamp)
              for index, file in enumerate(files):
                  if isfile(join(self.path, file)):
                      self.readAndMoveFile({"dest": destination, "name": file, "data": open(join(self.path, file))})
  
      def readAndMoveFile(self, fileData):
  
          print("\nArchivo:%s\n\n%s\n" % (fileData["name"], fileData["data"].read()))
  
          #El archivo debe ser cerrado para que se mueve
          fileData["data"].close()
          if not exists(fileData["dest"]):
              os.makedirs(fileData["dest"])
          try:
              shutil.move(join(self.path, fileData["name"]), fileData["dest"])
              print("\nArchivo \"%s\" movido \"%s\" a la carpeta.\n" % (fileData["name"], fileData["dest"]))
          except WindowsError as e:
              print(e)
  
      def listFiles(self):
          if self.path:
              return [file for file in os.listdir(self.path)]
          return None
  
      def stopWatching(self):
          print("\nNot watching.\n")
          self.timer.cancel()
  
      def complete(self):
          after = self.listFiles()
          added = [file for file in after if not file in self.lock]
          self.printFilesData(added)
          self.lock = after
          self.timer = Timer(5.0, self.complete)
          self.timer.start()
  
      def startWatching(self):
          if(self.path):
              self.lock = self.listFiles()
              print("\nDirectorio que se esta observando %s...\n" % self.path)
              self.printFilesData(self.lock)
              self.timer = Timer(5.0, self.complete)
              self.timer.start()
          else: print("Ruta sin definir.")
  
  class Main():
  
      def __init__(self):
          self.reader = FileReader("C:\\Test")
          self.reader.startWatching()
  
  
  if __name__ == '__main__':        
      Main()
  </code></pre>
  
  <p>I know I have to add the import logging and also:</p>
  
  <pre><code>logging.debug()
  logging.info()
  logging.warning()
  logging.error()
  logging.critical()
  </code></pre>
  
  <p>But I don't know how to apply  or where to put them</p>