# Streamlit Logging with Python Logger

**URL:** <https://discuss.streamlit.io/t/streamlit-logging-with-python-logger/51951>\
**Category:** Using Streamlit\
**Tags:** logs\
**Created:** [September 21, 2023, 8:24pm UTC](https://discuss.streamlit.io/t/streamlit-logging-with-python-logger/51951 "2023-09-21T20:24:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Commando-Brando](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/commando-brando/32/31125_2.png) [@Commando-Brando](https://discuss.streamlit.io/u/Commando-Brando)\
**Post date:** [September 21, 2023, 8:24pm UTC](https://discuss.streamlit.io/t/streamlit-logging-with-python-logger/51951/1 "2023-09-21T20:24:38Z")

</div>

Hey guys I am experiencing weird behavior in my Streamlit application. I host my own Streamlit application on my own server and I would like to use the python logging library to do so but I am running into some unexpected behaviour.

Whenever I start my app which just consists of the following code:

(menv) PS C:\code \> streamlit run .\src\test.py

```py
import logging
from logging import getLogger

import streamlit as st

print("---------------------------")
app_logger = getLogger()
app_logger.addHandler(logging.StreamHandler())
app_logger.setLevel(logging.INFO)
app_logger.info("best")
print("---------------------------")
st.info("Something went wrong please contact us about this error if it persists.")

```

I get the following output:

```auto
  You can now view your Streamlit app in your browser.

  Network URL: http://10.6.2.242:8501/stream
  External URL: http://129.115.2.66:8501/stream

---------------------------
best
---------------------------
---------------------------
best
best
---------------------------
---------------------------
best
best
best
---------------------------

```

After I refresh my webapage I get this output:

```auto
---------------------------
best
best
best
best
---------------------------

```

Not sure what is going on here but if anyone can help me resolve this I would greatly appreciate it.

Adding here also a mention that I found a post on [stack overflow](https://stackoverflow.com/questions/76474732/why-is-the-code-executed-multiple-times-whenever-streamlit-is-started) that has some upvotes describing similar behavior

---

<div class="post-metadata">

**Author:** ![Goyo](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/goyo/32/28219_2.png) [@Goyo](https://discuss.streamlit.io/u/Goyo)\
**Post date:** [September 22, 2023, 7:11am UTC](https://discuss.streamlit.io/t/streamlit-logging-with-python-logger/51951/2 "2023-09-22T07:11:27Z")

</div>

You are adding a handler to the logger on each rerun or refresh.

---

<div class="post-metadata">

**Author:** ![Commando-Brando](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/commando-brando/32/31125_2.png) [@Commando-Brando](https://discuss.streamlit.io/u/Commando-Brando)\
**Post date:** [September 22, 2023, 2:27pm UTC](https://discuss.streamlit.io/t/streamlit-logging-with-python-logger/51951/3 "2023-09-22T14:27:45Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [September 24, 2023, 2:28pm UTC](https://discuss.streamlit.io/t/streamlit-logging-with-python-logger/51951/4 "2023-09-24T14:28:09Z")

</div>

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