Logging from child page in multi page app

I am trying to do logging from multi page app.
I have run the Home .py like this
python -m streamlit run Home_v1.py --logger.level=warning 2>ā€˜app_log.logā€™

In the above page the logging is happening fine.
Here is the code in the Home.py


logger = get_logger(__name__)

logger.info('Home info ' + str(dt.datetime.now()))

logger.warning('Home warning ' + str(dt.datetime.now()))

logger.debug('Home debug ' + str(dt.datetime.now()))

Then i have a childpage.py where i have used the logging same code for testing
but when i click on the child page and it comes up logging does not seem to be happening from the child page. Any suggestions or advise appreciated.
Thanks
Sai

1 Like

Hi @Sai_SaiGraph! :wave:

I havenā€™t tried your solution, but I once created a little script that allows me to log in to any page of a multipage app.

Here it is below:

import streamlit as st

# Hardcoded password
correct_password = "one"

def check_password():
    """Returns `True` if the user has the correct password."""

    # Initialize 'password_correct' if it's not in the session state
    if "password_correct" not in st.session_state:
        st.session_state["password_correct"] = False

    # If the password has already been entered correctly, don't ask again
    if st.session_state.password_correct:
        return True

    # Initialize 'password' if it's not in the session state
    if "password" not in st.session_state:
        st.session_state["password"] = ""

    def password_entered():
        """Checks whether a password entered by the user is correct."""
        if st.session_state.password == correct_password:
            st.session_state.password_correct = True
        else:
            st.session_state.password_correct = False

    # Password not correct, show input + error.
    st.text_input(
        "Please authenticate to access the pages",
        type="password",
        on_change=password_entered,
        key="password",
    )
    if st.session_state.password_correct:
        return True
    elif st.session_state.password:
        st.error("šŸ˜• Password incorrect")
    return False

Feel free to try it and leave me feedback! :hugs:

Best wishes,

Charly

Thanks Charlie for your response. But i am talking about logger logging not authentication log inā€¦ i think your script refers to authentication loginā€¦ please correct meā€¦ Thank you againā€¦
Sai

This worked for me:

import logging

logging.basicConfig(filename=ā€˜app.logā€™, filemode=ā€˜wā€™, format=ā€˜%(name)s - %(levelname)s - %(message)sā€™)

logging.warning(ā€˜This will get logged to a fileā€™)

logging.debug(ā€˜This is a debug messageā€™)

logging.info(ā€˜This is an info messageā€™)

logging.warning(ā€˜This is a warning messageā€™)

logging.error(ā€˜This is an error messageā€™)

logging.critical(ā€˜This is a critical messageā€™)

1 Like

Oops, my mistake!

Iā€™m not familiar with Logger, and I thought the problem was about authentication logging, not server logging.

Anyway, glad you were able to find a solution to your issue! :blush:

Best,
Charly

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