title: How to append the logs in python
body: <p>There are two files named file1 and file2 in the python project.</p>
  
  <p>In file1.py , Iam capturing the log to file 'sample.log' and executing the file2.py through os.system() command.
  In file2.py, I am opening the sample log file sample.log in appending mode and sending logs to that file.</p>
  
  <p>I have executed the file1.py, even though I have opened the log file(file2.py) in append mode , I am unable to see the file2.py log.
  File2 contents are overridden by file1 contents.</p>
  
  <p>How Can I append file2.py logs with file1.py logs in sample.log?</p>
  
  <p><strong>file1.py</strong></p>
  
  <pre><code>import logging
  import os
  
  logFile = 'sample.log'
  logging.basicConfig( filename = logFile,filemode = 'w',level = logging.DEBUG,format = '%(asctime)s - %(levelname)s: %(message)s',\
                       datefmt = '%m/%d/%Y %I:%M:%S %p' )
  
  logging.debug("Starting of the file1")
  
  os.system("python file2.py")
  
  for i in range(0,2):
      logging.debug("Iam in file1")
  </code></pre>
  
  <p><strong>file2.py:</strong></p>
  
  <pre><code>import logging
  
  logFile = 'sample.log'
  logging.basicConfig( filename = logFile,filemode = 'a',level = logging.DEBUG,format = '%(asctime)s - %(levelname)s: %(message)s',\
                       datefmt = '%m/%d/%Y %I:%M:%S %p' )
  
  for i in range(0,2):
     logging.debug("Iam in file2")
  </code></pre>
  
  <p>Need the output like this</p>
  
  <blockquote>
    <p>03/06/2015 08:02:03 PM - DEBUG: Starting of the file1</p>
    
    <p>03/06/2015 08:02:03 PM - DEBUG: Iam in file2</p>
    
    <p>03/06/2015 08:02:03 PM - DEBUG: Iam in file2</p>
    
    <p>03/06/2015 08:02:03 PM - DEBUG: Iam in file1</p>
    
    <p>03/06/2015 08:02:03 PM - DEBUG: Iam in file1</p>
  </blockquote>
  
  <p>but getting like this:</p>
  
  <blockquote>
    <p>03/06/2015 08:02:49 PM - DEBUG: Starting of the file1</p>
    
    <p>03/06/2015 08:02:49 PM - DEBUG: Iam in file1</p>
    
    <p>03/06/2015 08:02:49 PM - DEBUG: Iam in file1</p>
  </blockquote>
  
  <p>Could someone help in this to get my expected output, Thanks in Advance</p>