title: How to add custom data in Python logs
body: <p>I am using python logging.</p>
  
  <p>Once I get a handle to logger object, I do the following to log</p>
  
  <pre><code>logger.info("this is my log message") 
  </code></pre>
  
  <p>My requirement is this:</p>
  
  <ol>
  <li><p>In the above custom log info message, I would want to pass more parameters like the following: </p>
  
  <pre><code>custom_name = "DISPLAY"
  logger.info("this is my log message", custom_name)
  </code></pre></li>
  <li><p>custom_name parameter should be consumed by the log formatter's <code>custom_name</code> placeholder as shown below</p>
  
  <pre><code>formatter = logging.Formatter('%(asctime)s %(custom_name)s:%(name)s %(message)s')
  </code></pre></li>
  </ol>
  
  <p>I read articles, stackoverflow posts, python logging documentation. I could only find how to create custom placeholders in the formatter.
  I am not sure how to pass those custom placeholder values from the log statement itself. Can someone point me to a resource or let me know how to accomplish this ?</p>
  
  <h3>Edit:</h3>
  
  <p>I could do something like this</p>
  
  <pre><code>import logging
  
  CUSTOM_VAR= 'myCustomVarValue'
  
  
  class ContextFilter(logging.Filter):
  
      def filter(self, record):
          record.CUSTOM_VAR= CUSTOM_VAR
          return True
  
  FORMAT = '%(CUSTOM_VAR)s %(asctime)s - %(levelname)s - %(message)s'
  logging.basicConfig(format=FORMAT, datefmt='%d/%m/%Y %H:%M:%S')
  
  logger = logging.getLogger(__name__)
  logger.addFilter(ContextFilter())
  
  logger.info("'this is info message")
  </code></pre>
  
  <p>The above works fine. However, <code>CUSTOM_VAR</code> is a static value. How can I dynamically pass this value from <code>log.info</code> ??</p>