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?
Thanks.
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?
Thanks.
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)
handler.setLevel(logging.INFO)
app.server.logger.addHandler(handler)
app.run_server()
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
Cheers!
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.addHandler(handler)
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â:
app.server.logger.addHandler(handler)
app.run_server()