title: Plotly Dash: Use SMTP logging handler when debug is false
body: <p>In Plotly Dash, I am trying to</p>
  <ol>
  <li>determine if I am running in debug mode, and</li>
  <li>change the logging handler to an SMTPHandler, only when the app is not running in Debug mode</li>
  </ol>
  <p>What I tried:</p>
  <pre><code>import dash
  
  app = dash.Dash(__name__)
  
  if app.server.debug is False:
      print(&quot;Not in Debug mode&quot;)
      # app.logger.addHandler(mail_handler)
  
  if __name__ == '__main__':
      app.run_server(debug=True, use_reloader=True)
      print(f&quot;app.server.debug is {app.server.debug}&quot;)  # This code only executes after the server is shut down
  </code></pre>
  <p>I tried <code>app.server.debug</code> (and <code>app.server.config[&quot;DEBUG&quot;]</code>) but both always return False. So I am not able to determine if the app is actually in debug mode or not.</p>
  <p>This is my console output:</p>
  <blockquote>
  <pre><code>Not in Debug mode
  Dash is running on http://127.0.0.1:8050/
  
   * Serving Flask app 'example_code' (lazy loading)
   * Environment: production
     WARNING: This is a development server. Do not use it in a production deployment.
     Use a production WSGI server instead.
   * Debug mode: on
  Not in Debug mode
  </code></pre>
  </blockquote>
  <p>I assume this confusion is because the <code>FLASK_DEBUG</code> environment variable is not set, but even so, it does say <strong><code>* Debug mode: on</code></strong> so how to identify this during runtime?</p>
  <p>And finally where do I add this debug mode check and change the handler - the debug is set in <code>app.run_server()</code> but adding any code immediately after that only executes after the server is shut down.</p>