title: Set Python Logging to overwrite log file when using dictConfig?
body: <p>I'm using <code>dictConfig()</code> to configure my logging. I want the process to overwrite the specified log file every time the process is run. How do I do this?</p>
  
  <p>I see <code>filemode</code> as a setting in <code>basicConfig()</code> but I can't figure out where to put this in the <code>dictConfig()</code> configuration.</p>
  
  <p>I've tried this but get an <code>unexpected keyword argument 'filemode'</code> error. I've tried it in a few other places too. Python logging docs are confusing as hell!</p>
  
  <pre><code>LOG_PATH                    = os.path.join(PROJECT_PATH,'logs')
  LOG_FILE_NAME               = 'log.'+main.__file__+'.'+time.strftime("%Y-%m-%d")
  LOG_FILE_PATH               = os.path.join(LOG_PATH,LOG_FILE_NAME)
  LOGGING_CONFIG = {
      'version': 1,
      'disable_existing_loggers': False,
      'formatters': { 
          'standard': { 
              'format': '[%(levelname)s] %(message)s - [pid:%(process)d - %(asctime)s - %(name)s]',
          },
      },
      'handlers': {
          'console': {
              'level': 'DEBUG',
              'formatter': 'standard',
              'class': 'logging.StreamHandler',
          },
          'file': {
              'level': 'INFO',
              'formatter': 'standard',
              'class': 'logging.FileHandler',
              'filename': LOG_FILE_PATH,
              'filemode': 'w',
          },
      },
      'loggers': {
          '': { 
              'handlers': ['console','file'],
              'level': 'DEBUG',
              'propagate': True
          },
      },
  }
  logging.config.dictConfig(os.path.join(LOGGING_CONFIG))
  logger = logging.getLogger(__name__)
  logger.debug('logger configured')
  </code></pre>
  
  <p><strong>ANSWER</strong></p>
  
  <hr>
  
  <p>Thanks to @Vinay Sajip for his selected answer below. Here is my updated configuration that now overwrites the specified log file every time the process is run. I simply added <code>LOGGING_CONFIG['handlers']['file']['mode'] = 'w'</code>.</p>
  
  <pre><code>LOG_PATH                    = os.path.join(PROJECT_PATH,'logs')
  LOG_FILE_NAME               = 'log.'+main.__file__+'.'+time.strftime("%Y-%m-%d")
  LOG_FILE_PATH               = os.path.join(LOG_PATH,LOG_FILE_NAME)
  LOGGING_CONFIG = {
      'version': 1,
      'disable_existing_loggers': False,
      'formatters': { 
          'standard': { 
              'format': '[%(levelname)s] %(message)s - [pid:%(process)d - %(asctime)s - %(name)s]',
          },
      },
      'handlers': {
          'console': {
              'level': 'DEBUG',
              'formatter': 'standard',
              'class': 'logging.StreamHandler',
          },
          'file': {
              'level': 'INFO',
              'formatter': 'standard',
              'class': 'logging.FileHandler',
              'filename': LOG_FILE_PATH,
              'mode': 'w', # &lt;=== HERE IS THE CHANGE
          },
      },
      'loggers': {
          '': { 
              'handlers': ['console','file'],
              'level': 'DEBUG',
              'propagate': True
          },
      },
  }
  logging.config.dictConfig(os.path.join(LOGGING_CONFIG))
  logger = logging.getLogger(__name__)
  logger.debug('logger configured')
  </code></pre>