title: Django logging custom attributes in formatter
body: <p>How can Django use logging to log using custom attributes in the formatter? I'm thinking of logging the logged in username for example.</p>
  
  <p>In the <code>settings.py</code> script, the LOGGING variable is defined:</p>
  
  <pre><code>LOGGING = {
      'version': 1,
      'disable_existing_loggers': False,
      'filters': {
          'require_debug_false': {
              '()': 'django.utils.log.RequireDebugFalse'
          },
      },
      'formatters' : {
          'info_format' : {
              'format' : '%(asctime)s %(levelname)s - %(message)s',
          },
      }
  }
  </code></pre>
  
  <p>I wish to use a format, something like:</p>
  
  <pre><code>'format' : '%(asctime).19s %(levelname)s - %(username)s: %(message)s'
  </code></pre>
  
  <p>Where username would be the currently logged in user. Maybe any other kind of session's variables may be added here.</p>
  
  <p>A workaround here is to use the <code>extra</code> parameter on the logger methods, which receives a dictionary with the keys as the strings I want to use on the format string:</p>
  
  <pre><code>logger.info(message, extra={'username' : request.user.username})
  </code></pre>
  
  <p>Another (ugly) workaround would be to build the message attribute to include the things that are not part of the default attributes that logging formatters have.</p>
  
  <pre><code>message = request.user.username + " - " + message
  logger.info(message)
  </code></pre>
  
  <p>But, is there a way to set up the format string with certain attributes and make Django give them automatically to the logging API? If %(username)s for example, the request.user.username, of any others perhaps...</p>