title: Can I make Python output exceptions in one line / via logging?
body: <p>I am using AWS and use AWS cloudwatch to view logs. While things should not break on AWS, they could. I just had such a case. Then I searched for <code>Traceback</code> and just got the lines</p>
  
  <pre><code>Traceback (most recent call last):
  </code></pre>
  
  <p>without the actual traceback. I have a working structured logging setup (see <a href="https://stackoverflow.com/a/48202500/562769">other question</a>) and I would like to get tracebacks in a similar way.</p>
  
  <p>So instead of:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/math/Desktop/test.py", line 32, in &lt;module&gt;
      adf
  NameError: name 'adf' is not defined
  </code></pre>
  
  <p>something like</p>
  
  <pre><code>{"message": "Traceback (most recent call last):\n      File \"/home/math/Desktop/test.py\", line 32, in &lt;module&gt;\n        adf\n    NameError: name 'adf' is not defined", "lineno": 35, "pathname": "/home/math/Desktop/test.py"}
  </code></pre>
  
  <p>or even better also with the string in a JSON format.</p>
  
  <p>The only way to achieve this I can think of is a giant try-except block. Pokemon-style. Is there a better solution?</p>