title: How to add custom parameter into Python logging formatter?
body: <p>I'm using standard Python logging module with Flask framework. I want to write logs to file with the all records of users actions with custom parameter - %(username)s to logging.Formatter:</p>
  
  <pre><code>admin - 2013-10-11 15:11:47,033 action0
  user1 - 2013-10-11 15:11:48,033 action1
  user2 - 2013-10-11 15:11:49,033 action2
  admin - 2013-10-11 15:11:50,033 action3
  </code></pre>
  
  <p>I'm using RotatingFileHandler:</p>
  
  <pre><code>def get_user_name():
      return session.get("username", "")
  
  file_handler = RotatingFileHandler(fname, maxBytes=1 * 1024 * 1024, backupCount=5)
  file_handler.setLevel(logging.DEBUG)
  file_handler.setFormatter(logging.Formatter(
      '%(username)s - %(asctime)s %(levelname)-10s %(message)s  [in %(pathname)s:%(lineno)d]'
  )) # how to insert get_user_name() instead %(username)s?
  
  app.logger.addHandler(file_handler)
  </code></pre>
  
  <p>What is the right way to do such logger? Thanks.</p>