Is there an option to save logs?
There is an option to use loggings inside as a write on the screen.
But when trying to save logs, it does not work, it does not create the logging file.
Hi @BugzTheBunny,
Thank you for sharing with the Streamlit community!
This post covers how to enable logging via the command line. You mentioned that you have already tried to save logs â can you provide a code snippet or screenshot of the commands youâve already tried?
Best,
Caroline
Hi @Caroline !
The code is pretty simple:
import streamlit as st
import logging
logging.basicConfig(filename='example.log')
logging.debug('This message should go to the log file')
But for some reason the exmaple.log file is not being created, and u did run it now using
streamlit run app.py --logger.level=debug
Hi @BugzTheBunny,
You will need to add a parameter to what youâre entering in the command line that will redirect stderr to a file. The syntax of this parameter should be â2>logfilename.txtâ
For example:
streamlit run streamlit_app.py --logger.level=debug 2>logs.txt
Best,
Caroline
Okay, thatâs great for a run command, is there an option to make it in a config file?
Thanks for the answer!!
Hey!
Thanks again, really helpful.
But I actually meant is there an option to use the â2> logs.logâ into the config?
If not thatâs also okay, Iâm using docker, so thatâs not really an issue, just wanted to know 
Hi @BugzTheBunny,
That piece is just redirecting stderr to a different file, so you would need to include it in the command unfortunately.
Best,
Caroline
Hi again⌠this is not working when using docker 
I run the code, but while using docker for this, it does not work when using docker⌠
the output is still being seen in the console, rathar then being writtenin the fileâŚ
beyond that, the file itself is not being created.
DockerFile:
FROM python:3.8-slim-buster
COPY streamlit_src /app
COPY aoi_defects_clustering/src /app/src
COPY unit_level_analysis /app/unit_level_analysis
COPY machines.csv /app/machines.csv
WORKDIR /app
RUN python -m pip install --upgrade pip
RUN pip install -r requirements.txt
EXPOSE 8889
ENTRYPOINT ["streamlit","run","--server.port","8889","app.py","--logger.level=info","2>","streamlit_logs.log"]
Am I missing something?
Found a solution!
FROM python:3.8-slim-buster
COPY streamlit_src /app
...
...
COPY run_app.sh /app/run_app.sh
RUN python -m pip install --upgrade pip
RUN pip install -r requirements.txt
RUN chmod +x /app/run_app.sh
WORKDIR /app
EXPOSE 8889
ENTRYPOINT ["/bin/bash"]
CMD ["./run_app.sh"]
run_app.sh:
streamlit run --server.port 8889 app.py --logger.level=info 2> streamlit_logs.log
Nonetheless, it would be a nice feature if we could also enable file logging in config.toml besides the log level 
A small suggestion for improving your Dockerfile:
WORKDIR /app
COPY . .
and add a .dockerignore file to the repo so that only the wanted files get copied to the container image.
Will COPY . . just copy all of the content? if so, thatâs not what i need unfortunately, there are a lot of items i need to ignore, si this is a shorter way.
Or im missing something?
Yes.
But you can use also inverted logic in the ignore files, for example
# Ignore everything
*
# But not these files...
!file1.py
!file2.py
Great to know!
Im pretty new to docker, been using it for about a month only, and would not really call myself a poweruser of this.
Will use it in the future, but at this point the shorter way is just to copy these 4 files 
Thanks a lot tho!
As far as i know, the .dockerignore uses the same syntax/logic as the .gitignore files.
So you can use this knowledge in different cases.
Will dig deeper then
(10 months later) ![]()
I have a similar, but slightly different problem.
Running my app locally, I can download (from within the app) a log file containing all the log-messages.
However, when I run the hosted app, I see the logs only in the little âmanage appâ-shell.
The file that I download is always empty!
Any help would be appreciated.
Here are some screenshots and a link to the app:
Hosted
Local
app
I suspected that loggingâs config is not correct.
So, just for the sake of debugging things, I tried a new, easy to config library called lovely-logger.
Locally, everything works fine, but this time the online version produces a file with duplicated messages
Any idea what might be misconfigured?
I tried to configure the logger
In a function, that is called only once per session.
Thanks for your help!



