1

I would like to have 2 loggers, one that logs a summary of what my code is doing, and one that logs specific details. I would like to have the loggers write to different files in different locations as well. However my loggers currently write to the same file.

# Create MAIN Log
logging.basicConfig(filename=main_log_path,level=logging.INFO)
logging.getLogger("requests").setLevel(logging.WARNING)
# Create Details logger
logging.basicConfig(filename= detailed_log_path,level=logging.INFO)
logging.getLogger("requests").setLevel(logging.WARNING)

main_logger = logging.getLogger('Log_Summary')
detailed_logger = logging.getLogger('Detailed_Summary')

main_logger_handler = logging.FileHandler(main_log_path)
main_logger.addHandler(main_logger_handler)

detailed_logger_handler = logging.FileHandler(main_log_path)
detailed_logger.addHandler(detailed_logger_handler)

main_logger.info("this is the main logger")
detailed_logger.info("this is the detailed logger")
1
  • That's because your file handlers are both setup with main_log_path. Commented Aug 13, 2016 at 2:47

1 Answer 1

1
detailed_logger_handler = logging.FileHandler(main_log_path)
detailed_logger.addHandler(detailed_logger_handler)

Change the main_log_path to something else. Right now both the loggers point to the same file. You need different paths to log to different files.

Sign up to request clarification or add additional context in comments.

Comments

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.