Disable or change level for streamlit logs

Hi,

my config.toml has

[logger]
level = "debug"

I’m running a multi-page web app based on streamlit==1.30.0

In my pages, I’m using this logging configuration:

import streamlit.logger
logger = streamlit.logger.get_logger("name_of_the_page")
logger = streamlit.logger.get_logger("name_of_the_module_i_want_logs")

This is working as expected, hence I get all DEBUG logs from all the pages/modules I’m including.
But I would like to achieve the following:

  • Get INFO logs for streamlit or disable them completely
  • Get DEBUG logs for everything else

Is it possible?

1 Like

Hello @espogian,

For your application logs, you can configure Python’s logging library directly in your code to set different logging levels for different parts of your application.

import logging
import streamlit as st

logging.basicConfig(level=logging.DEBUG)

st_logger = logging.getLogger('streamlit')
st_logger.setLevel(logging.INFO)

# Your page/module logger can remain at DEBUG level or be set explicitly
logger = logging.getLogger("name_of_the_page")
logger.debug("This is a DEBUG message from my page.")

st.write("Check your console for the logging output.")

If you want to disable Streamlit logs entirely, you can set Streamlit’s logger level to WARNING or higher, which will suppress INFO and DEBUG logs:

st_logger.setLevel(logging.WARNING)

Hope this helps!

Kind Regards,
Sahir Maharaj
Data Scientist | AI Engineer

P.S. Lets connect on LinkedIn!

➤ Want me to build your solution? Lets chat about how I can assist!
➤ Join my Medium community of 30k readers! Sharing my knowledge about data science and AI
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ 100+ FREE Power BI Themes: Download Now

3 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.