title: Check if Flask request context is available
body: <p>I want to log some data from context variables (<code>request</code>, <code>session</code>) when logging during a Flask request, but use default behavior if not.</p>
  
  <p>I'm using a <code>try ... except</code> block in <code>logging.formatter</code>. Is there a better way to check for a request context?</p>
  
  <pre><code>try:
      record.user = session['user_name']
      record.very_important_data = request.super_secret
  except Exception:
      record.user = None
  </code></pre>