title: Python logging into file as a dictionary or JSON
body: <p>I am trying to set up logging where I can log in both stdout and on to a file. This i have accomplished using the following code: </p>
  
  <pre><code>logging.basicConfig(
          level=logging.DEBUG, format='%(asctime)-15s %(levelname)-8s %(message)s',
          datefmt='%a, %d %b %Y %H:%M:%S', handlers=[logging.FileHandler(path), logging.StreamHandler()])
  </code></pre>
  
  <p>The output of this something like this:</p>
  
  <pre><code>2018-05-02 18:43:33,295 DEBUG    Starting new HTTPS connection (1): google.com
  2018-05-02 18:43:33,385 DEBUG    https://google.com:443 "GET / HTTP/1.1" 301 220
  2018-05-02 18:43:33,389 DEBUG    Starting new HTTPS connection (1): www.google.com
  2018-05-02 18:43:33,490 DEBUG    https://www.google.com:443 "GET / HTTP/1.1" 200 None
  </code></pre>
  
  <p>What I am trying to accomplish is logging this output to a file not as it is printing to stdout, but as a dictionary or JSON object similar to something like this (while keeping the stdout as it is at the moment):</p>
  
  <p><code>[{'time': '2018-05-02 18:43:33,295', 'level': 'DEBUG', 'message': 'Starting new HTTPS connection (1): google.com'}, {...}, {...}]</code></p>
  
  <p>Is this doable? I understand that I can post process this log file after my process is finished, but I am looking for a more elegant solution because certain things i am logging are quite big objects themselves. </p>