title: How to write logging messages to a file
body: <p>I am trying to use the Python <code>logging</code> library. Instead of printing the messages in the console, I want to write them to a file. Based on the <a href="https://docs.python.org/2/library/logging.handlers.html#logging.FileHandler" rel="nofollow noreferrer">documentation</a> , I'm a little unsure of how to do this. First I imported the <code>logging</code> in and then I created my logging object. Note: I am a little unsure of the <code>name</code> parameter when doing this. Is this suppose to be a filename that has a full filepath? A random name that I just make up?</p>
  
  <pre><code>foldname = "chk_logs"
  logFileName = os.path.join(path.abspath(path.curdir),foldname + "\\Fields_Log_" + timeStamp + ".txt")             #logging
  if os.path.isdir(foldname)==False:
      os.mkdir(foldname)
  logFile = open(logFileName, "w")
  
  format="%(asctime)s [%(levelname)s] %(message)s"
  logging.basicConfig(fileName=logFile, format=format, level=10)
  logger = logging.getLogger('name')  
  </code></pre>
  
  <p>So, suppose I want to write a message to the <code>logFile</code> from my <code>logger</code>.</p>
  
  <pre><code>   logger.debug("Test")
  </code></pre>
  
  <p>This essentially does nothing, even after I use <code>logFile.close()</code>. If I try this:</p>
  
  <pre><code>logFile.write(str(logger.debug("Test")))
  </code></pre>
  
  <p>it basically write 'None' in the <code>.txt</code> file. There must be a simple way to do this; what am I doing wrong?</p>