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.
Is there an option to save logs?
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?
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
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”
streamlit run streamlit_app.py --logger.level=debug 2>logs.txt
Okay, that’s great for a run command, is there an option to make it in a config file?
Thanks for the answer!!
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
That piece is just redirecting stderr to a different file, so you would need to include it in the command unfortunately.
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.
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"]
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?
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
So you can use this knowledge in different cases.
Will dig deeper then