0
我想要2個記錄器,一個記錄我的代碼正在做什麼的摘要,另一個記錄特定的細節。我想讓記錄器寫入不同位置的不同文件。但是我的記錄器目前正在寫入同一個文件。將不同級別記錄到多個文件Python
# 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")
這是因爲你的文件處理程序都是用'main_log_path'設置的。 –