✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Redirect Logging to File / Directory

When running a dash app, all the HTTP responses and errors are shown in the CLI by default. Is there a way in Dash to send this logging to a file or a file in a folder instead for debugging at a later time? Or any other ways to do this?


1 Like

Googling “Flask file logger”, I found this: https://gist.github.com/ibeex/3257877

Adapting this to Dash would look something like:

import logging
from logging.handlers import RotatingFileHandler

import dash

app = dash.Dash()

if __name__ == '__main__':
    handler = RotatingFileHandler('foo.log', maxBytes=10000, backupCount=1)

I haven’t tested this, but I’d recommend searching for something along these lines. Be sure to let us know what you end up with!


@tbone did chris’s solution work?
My file comes out empty.
Could you please share what you did

Try using this, I just tested it and it works
import logging
from logging.handlers import RotatingFileHandler

import dash
import dash_html_components as html

logger = logging.getLogger(‘my_logger’)
handler = RotatingFileHandler(‘ttt.log’, maxBytes=10000, backupCount=1)

logger.warning(‘start application’)
app = dash.Dash()
app.layout = html.Div([
html.H3(children=“Hello From the Dash app”)
logger.warning(‘end application’)

if name == ‘main’: