Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply logger config to all logger instances #7858

Open
4 tasks done
kaisa-kucherenko opened this issue Dec 19, 2023 · 9 comments · May be fixed by #9416
Open
4 tasks done

Apply logger config to all logger instances #7858

kaisa-kucherenko opened this issue Dec 19, 2023 · 9 comments · May be fixed by #9416
Assignees
Labels
feature:config Related to config settings type:enhancement Requests for feature enhancements or new features

Comments

@kaisa-kucherenko
Copy link

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

Starting from version 1.22.0 of Streamlit and above, the options in the config.toml file under the [logger] section no longer function. I am currently in the process of upgrading from Streamlit version 1.10.0 to the latest 1.29.0 and have observed that logs cease to display while the application is running.
The logging level is set to 'Info' in the file, but logs are only appearing from the 'Warning' level and above. Additionally, the formatting doesn't match the configuration file.

config.toml
[logger]
level = "info"
messageFormat = "%(asctime)s - %(levelname)s %(filename)s:%(lineno)-4d - %(message)s"

Reproducible Code Example

import streamlit as st
import logging

log = logging.getLogger("my_tool_logger")

st.write("Some text of page")

log.info("Page loaded")

Steps To Reproduce

  1. Install streamlit version 1.29.0
  2. Insert the following line into the [logger] section of the config.toml file: level = "info"
  3. Execute the code example I have provided."

Expected Behavior

Logs are displayed in the standard output.
https://img.serpstat.com/kaisa/2023-12-19_ZFDITjqD.png

Current Behavior

When the logging level is set to 'info,' logs do not appear in the standard output. The message format does not conform to the configuration specified in the 'config.toml' file.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.29.0
  • Python version: 3.8
  • Operating System: Ubuntu 22.04
  • Browser: Chrome

Additional Information

I tested this on every version from 1.29.0 to 1.21.0, and it appears that it broke starting from version 1.22.0. It worked fine in version 1.21.0.

@kaisa-kucherenko kaisa-kucherenko added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Dec 19, 2023
@lukasmasuch lukasmasuch changed the title [logger] section in config.toml not working from version 1.22.0 Apply logger config to all logger instances Dec 21, 2023
@lukasmasuch lukasmasuch added type:enhancement Requests for feature enhancements or new features feature:config Related to config settings and removed type:bug Something isn't working status:needs-triage Has not been triaged by the Streamlit team labels Dec 21, 2023
Copy link

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.

Visits

@streamlit streamlit deleted a comment from github-actions bot Dec 21, 2023
@lukasmasuch
Copy link
Collaborator

@kaisa-kucherenko Thanks for reporting this issue! I was able to reproduce this, but I think the logger settings are mostly for the Streamlit internal logging. And this is working as expected. If you like to apply the same settings to your logger instance, you can initialize it like this:

import logging

import streamlit as st
from streamlit.logger import get_logger

log = get_logger("my_tool_logger")

st.write("Some text of page")

But this is more like an internal API, so it might be changed in future versions. I'm also adding @kajarenc to this thread since he made some changes to the logger recently.

@kaisa-kucherenko
Copy link
Author

@lukasmasuch Thank you for the suggestion, but I find it a bit unclear. The documentation for config.toml and the logger section doesn't provide any clues about this issue. It seems like a bug. I came across this discussion: link to the GitHub issue.

@lukasmasuch
Copy link
Collaborator

Yep, I agree that we should clarify this a bit more in our docs. Maybe it's also an unexpected behavior, @kajarenc might be able to say more on this.

@kajarenc
Copy link
Collaborator

kajarenc commented Dec 21, 2023

Hey @kaisa-kucherenko, thank you for opening this issue!

You are right, the one implication that we have changed our root logger to a "streamlit" logger, is that just getting the logger via logging.getLogger does not apply configs from config.toml per se.

So my comment here is partially wrong.

The idea of that PR was to give streamlit app developers more freedom to configure their app logs, and not bound them with streamlit internal logger.

In order to keep the old behavior, you can either import get_logger from stremalit logger (as @lukasmasuch mentioned)

import logging

import streamlit as st
from streamlit.logger import get_logger

log = get_logger("my_tool_logger")

st.write("Some text of page")

or use "streamlit" logger explicitly

import streamlit as st
import logging

log = logging.getLogger("streamlit")

st.write("Some text of page")

log.info("Page loaded")

this should also work.

I agree that it is not clear from the documentation, so we should change docs to highlight the fact that logger configuration applies to streamlit logger.

@jrieke
Copy link
Collaborator

jrieke commented Jan 2, 2024

@kajarenc or @sfc-gh-dmatthews, can one of you update the docstring to make this more clear and close this issue?

@Seluj78
Copy link

Seluj78 commented Sep 6, 2024

Any updates on this ?

@sfc-gh-dmatthews sfc-gh-dmatthews linked a pull request Sep 6, 2024 that will close this issue
@sfc-gh-dmatthews
Copy link
Contributor

@jrieke I have a PR to update the description, but this issue is currently labeled as an enhancement request to change the behavior. Do you want this closed with the clarification "this setting is for Streamlit's internal logger" and "won't do" for the enhancement request? Or, do you want to keep this open as an enhancement request?

@jrieke
Copy link
Collaborator

jrieke commented Sep 10, 2024

Yeah I think we can close this issue once the docs changes are merged. I don't think we'll revert that back to the old setting again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:config Related to config settings type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants