streamlit icon indicating copy to clipboard operation
streamlit copied to clipboard

Add the ability to mute/disable messages logged by the Logger

Open skasero opened this issue 6 months ago • 5 comments

Checklist

  • [x] I have searched the existing issues for similar feature requests.
  • [x] I added a descriptive title and summary to this issue.

Summary

My team has created an API in Streamlit that makes many streamlit calls with no actually user loading up a web browser. I get thousands of messages that show this:

2025-06-13 05:56:58.507:streamlit.runtime.app_session:app_session.py:525:DEBUG: Ignoring event from non-current ScriptRunner: ScriptRunnerEvent.ENQUEUE_FORWARD_MSG
2025-06-13 05:56:58.508:streamlit.runtime.app_session:app_session.py:525:DEBUG: Ignoring event from non-current ScriptRunner: ScriptRunnerEvent.ENQUEUE_FORWARD_MSG

My feature request is looking to add a function that applies a Global Filter to log message. Similar to how urllib3 has a disable warnings function. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Why?

I'm an unable to easily debug my streamlit application when I get over 2000+ messages repeating the same message. I'd like a way to add a filter so that if the user wants, they can disable certain messages from being logged.

How?

I'd like to introduce a function inside logger.py that adds a Global Filter to loggers. I wanted to see if this was possible, and I have already created working code for this. Ideally, I'd like this feature to get added and would love feedback from Streamlit team if the team decided this is a good feature.

My current code would look like this when added to a streamlit python file.

from streamlit.logger import suppress_log_event
from streamlit.runtime.scriptrunner import ScriptRunnerEvent

suppress_log_event(ScriptRunnerEvent.ENQUEUE_FORWARD_MSG)

Additional Context

I'd like to volunteer for the solution for this issue.

skasero avatar Jun 13 '25 19:06 skasero

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Views

github-actions[bot] avatar Jun 13 '25 19:06 github-actions[bot]

I'm a bit confused why these log messages even show up in the first place. They shouldn't show if you just streamlit run your app, otherwise that's a bug. Can you add a bit more detail on how you run these apps?

jrieke avatar Jun 14 '25 15:06 jrieke

Hi @jrieke I'll give you some quick code to replicate it utilizing the API code provided by: https://gist.github.com/schaumb/d557dabf0beced7dfaa1be7acc09b1e4

And here is a quick streamlit app.py file.

import streamlit as st
import pandas as pd
import plotly.express as px
from st_route import st_route

@st_route(path=r"test", globally=True)
def test_api(**kwargs):
    df = pd.DataFrame({'x': [1,2,3], 'y': [4,5,6]})
    quick_plot(df)
    return 200, "Test"

def quick_plot(df):
    fig = px.line(df)
    st.plotly_chart(fig)

st.write("Test App")

After loading up http://127.0.0.1:8501 then you can perform a curl http://0.0.0.0:8501/test and inside the logs you'll see 2025-06-15 12:05:20.265 Ignoring event from non-current ScriptRunner: ScriptRunnerEvent.ENQUEUE_FORWARD_MSG

Make sure to enable DEBUG logs for streamlit.

It may not be a bug with streamlit as it wasn't designed to use API calls and may be an issue with st_route.py. But this feature still could be a good feature to add to suppress certain log message if the user wants. (Or at least I'd like that)

skasero avatar Jun 15 '25 19:06 skasero

Got it. Since this is a pretty special case and nothing we officially support, I think there's very little chance we'll add something for this at the moment, unless this issue gets more upvotes or we see other use cases. Note that the functions inside of streamlit.logger are internal and subject to change, so we don't want to add anything there that's publicly used, and this feature doesn't seem worth adding a dedicated, public API.

But since the log message here is anyway a DEBUG message, can't you just suppress it by setting logger.level in the config file, so the logger doesn't print debug messages?

jrieke avatar Jun 15 '25 21:06 jrieke

I could disable debug, but then this defeats the purpose of viewing all other debug messages, which are very helpful. My problem is that when I make many st. calls, it spams the logs and make debugging extremely hard.

skasero avatar Jun 15 '25 21:06 skasero

Yeah I can see that. As outlined above, I think we don't want to add a public API for this special case right now, but I'll keep the issue open and we can see how many upvotes it gets.

jrieke avatar Jun 17 '25 10:06 jrieke

For anyone in the future interested, b/c streamlit is using the logging package. I wrote a standalone script that will work Streamlit or any package that uses logging package.

https://gist.github.com/skasero/e1ea02b3bb411beae728bb89f8c8919e

Example of using this for Streamlit would be:

from logger_suppressor import suppress_log_messages
from streamlit.runtime.scriptrunner import ScriptRunnerEvent

suppress_log_messages(ScriptRunnerEvent.ENQUEUE_FORWARD_MSG)

skasero avatar Jul 01 '25 23:07 skasero