如何在不知道記錄器名稱的情況下使班級的記錄沉默?有問題的類是qualysconnect。Python:特定班級記錄器的setLevel
import logging
import qualysconnect.util
# Set log options. This is my attempt to silence it.
logger_qc = logging.getLogger('qualysconnect')
logger_qc.setLevel(logging.ERROR)
# Define a Handler which writes WARNING messages or higher to the sys.stderr
logger_console = logging.StreamHandler()
logger_console.setLevel(logging.ERROR)
# Set a format which is simpler for console use.
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# Tell the handler to use this format.
logger_console.setFormatter(formatter)
# Add the handler to the root logger
logging.getLogger('').addHandler(logger_console)
# 'application' code
logging.debug('debug message')
logging.info('info message')
logging.warn('warn message')
logging.error('error message')
logging.critical('critical message')
輸出時import qualysconnect.util
被註釋掉:
root : ERROR error message
root : CRITICAL critical message
輸出時import qualysconnect.util
保持在:
WARNING:root:warn message
ERROR:root:error message
root : ERROR error message
CRITICAL:root:critical message
root : CRITICAL critical message
我是來源的貢獻者,我懷疑這是解決方案:https://bitbucket.org/uWaterloo_IST_ISS/python-qualysconnect/issue/19/set-logger-name – paragbaxi
非常感謝您的確認! – paragbaxi
創建我自己的班級qualysapi。嘗試實現包級別日誌記錄。有什麼建議? – paragbaxi