Search code examples
streamlit

Overwriting text in File using Streamlit


I wrote the code for overwriting text in log file instead of appending it using Streamlit, but instead of overwriting it keeps appending the text. Can someone please help me with this? Below is my code.

import streamlit as st
import logging

logging.basicConfig(filename=app.log, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s',filemode='w')

logging.info('Application Started')

Solution

  • You're missing quotes in the filename argument.

    import logging
    import streamlit as st
    
    logging.basicConfig(filename="app.log", level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s", filemode="w")
    
    logging.info("Application Started")