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. Commented Feb 12, 2016 at 5:40
  • @apex-meme-lord, how? Commented 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)
Sign up to request clarification or add additional context in comments.

1 Comment

do I really need "logger = logging.getLogger('something')"?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.