0

I hosted my python application using flask. My script has two functions, depends on the input data it will decide the method, for each method I am writing a different log file.

My code looks like this,

my_flask.py

if input_data=="one":
     method_one()
else:
     method_two()

"""my functions"""
def method_one():
     logging.basicConfig(filename="method_one.log",level=logging.DEBUG,format="%(asctime)s:%(message)s")
     s="performing method one"
     logging.debug(s)
def method_two():
    logging.basicConfig(filename="method_two.log",level=logging.DEBUG,format="%(asctime)s:%(message)s")
    s="performing method two"
    logging.debug(s)

when I access this method at the very first time, if the first input_data is "one" then log is writing to method_one.log If I access method_two() when the input_data !="one", still the s is writing to method_one.log file

all the logs are logged based on which method is calling first.

how to handle this to write both the log files based on the condition, please help. Thanks in advance!

Pyd
  • 6,017
  • 18
  • 52
  • 109
  • 1
    Logging saves the very first configuration, use handlers to do your job. Try to call method_two and then method_one and you will see ) – Sergius Mar 20 '18 at 09:04
  • ya if we do like that, all logs will be saved in `method_two.log` . I want two different log files for two respective functions , – Pyd Mar 20 '18 at 09:15
  • how to use handlers, can you send any reference link – Pyd Mar 20 '18 at 09:15
  • 1
    https://stackoverflow.com/questions/11232230/logging-to-two-files-with-different-settings – Sergius Mar 20 '18 at 09:18
  • Thank you, that worked fine – Pyd Mar 20 '18 at 10:57

0 Answers0