title: Python Logging - Configuring Rotating File Handler From Config file
body: <p>I have the below config file which I am using to configure logging in my python modules , the issue with this is that it does not append the timestamp to the file-name , right now the log file created is file_handler.log but I want it to be file_handler-timestamp.log</p>
  <pre><code>{
  &quot;version&quot;: 1,
  &quot;disable_existing_loggers&quot;: true,
  &quot;formatters&quot;: {
    &quot;simple&quot;: {
      &quot;format&quot;: &quot;%(asctime)s %(levelname)s %(filename)s %(lineno)s %(message)s&quot;,
      &quot;datefmt&quot;: &quot;%Y-%m-%d %H:%M:%S&quot;
    }
  },
  &quot;handlers&quot;: {
    &quot;file_handler&quot;: {
      &quot;level&quot;: &quot;INFO&quot;,
      &quot;class&quot;: &quot;logging.handlers.TimedRotatingFileHandler&quot;,
      &quot;formatter&quot;: &quot;simple&quot;,
      &quot;filename&quot;: &quot;error.log&quot;,
      &quot;backupCount&quot;: 10,
      &quot;interval&quot; : 1,
      &quot;when&quot;: &quot;s&quot;,
      &quot;encoding&quot;: &quot;utf8&quot;
    }
  },
  &quot;loggers&quot;: { },
  &quot;root&quot;: {
    &quot;handlers&quot;: [
      &quot;file_handler&quot;
    ],
    &quot;level&quot;: &quot;DEBUG&quot;
  }
  }
  </code></pre>
  <p>Working code without config</p>
  <pre><code>import logging
  import time
  from logging.handlers import RotatingFileHandler
      
  logger = logging.getLogger('log_1')
  formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s', '%Y-%m-%d %H:%M:%S')
  handler = RotatingFileHandler('log' + time.strftime('_%Y%m%d-%H%M') + '.log', maxBytes=2000, backupCount=10)
  handler.setFormatter(formatter)
  logger.addHandler(handler)
  </code></pre>
  <p>Workaround code which updated the config dynamically when program is initiated</p>
  <pre><code>import logging.config
  import json
  import time
  
  fp = open(&quot;sample_config.json&quot;)
  config = json.load(fp)
  fp.close()
  config['handlers']['file_handler']['filename'] += time.strftime('_%Y%m%d-%H%M') + '.log'
  logging.config.dictConfig(config)
  </code></pre>