-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Importing streamlit adds StreamHandler to root logger #1248
Copy link
Copy link
Closed
Labels
type:enhancementRequests for feature enhancements or new featuresRequests for feature enhancements or new features
Description
Problem
When importing streamlit (without calling it via the cli), a StreamHandler is registered to the root logger. In my current project, I import Streamlit, but the script is not always executed as streamlit app - when running headless, it is not used.
import logging
print(logging.getLogger().handlers) # outputs '[]'
import streamlit
print(logging.getLogger().handlers) # now outputs '[<StreamHandler <stderr> (NOTSET)>]'In my opinion, no handler should be registerd when the library is just imported (should only happen when the script is executed via streamlit).
Solution
Would it be possible to only add the handler when the script is called via the streamlit run command?
Additional context
Since I am beginner using logging as well as streamlit, I am not sure whether this is in fact the intended behavior, but I did not expect the import of streamlit to change logging settings.
Version 0.56.0
$ pip freeze | grep streamlit
streamlit==0.56.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type:enhancementRequests for feature enhancements or new featuresRequests for feature enhancements or new features