0

I have multiple python scripts I run at the same time. They all located in the same directory. One of those is imported in another by "import". In those 2 files I have this:

script #1
log_file_name = "logs/somefile_name.log")
logging.basicConfig(filename=log_file_name) 


script #2
log_file_name = "logs/somefile_name2.log")
logging.basicConfig(filename=log_file_name) 

Again, script #2 is imported in script #1 because script #2 has some functions I need in the 1st one.

For some reason I see only one log file, although they have different names. Why is that? I think the settings of creating the logger get overwritten. How to fix it?

2
  • logging.basicConfig() is ignored after the first time it is called. The root logger in the module is meant to be used as a singleton. If you want to add more log files, you need to add new handlers. Feb 12, 2016 at 5:40
  • @apex-meme-lord, how?
    – Mr. Mister
    Feb 12, 2016 at 5:44

1 Answer 1

1

It's right in the documentation for logging.

log2 = logging.FileHandler('logs/somefile_name2.log')
logging.addHandler(log2)
1
  • do I really need "logger = logging.getLogger('something')"?
    – Mr. Mister
    Feb 12, 2016 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.