Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python日志从handleError获取对记录器的引用_Python_Logging_Python Logging - Fatal编程技术网

Python日志从handleError获取对记录器的引用

Python日志从handleError获取对记录器的引用,python,logging,python-logging,Python,Logging,Python Logging,我正在编写一个定制的Python日志处理程序,每当出现日志错误时,它就会将系统置于错误状态。为此,我在自定义处理程序中重写handleError()方法 一旦系统进入错误状态,我需要监视记录器,偶尔测试它是否恢复。为了做到这一点,我需要引用handleError()方法中出现错误的实际记录器 如何从记录器处理程序的handleError()方法访问记录器 我正在尝试做的示例: class MyFileHandler(WatchedFileHandler): def handleError

我正在编写一个定制的Python日志处理程序,每当出现日志错误时,它就会将系统置于错误状态。为此,我在自定义处理程序中重写handleError()方法

一旦系统进入错误状态,我需要监视记录器,偶尔测试它是否恢复。为了做到这一点,我需要引用handleError()方法中出现错误的实际记录器

如何从记录器处理程序的handleError()方法访问记录器

我正在尝试做的示例:

class MyFileHandler(WatchedFileHandler):
    def handleError(self, record):
        logger_that_had_the_error = ???????????
        put_system_in_error_state(f"Logging failure ({record.msg})")
        start_monitoring_logger(logger_that_had_the_error)
        super().handleError(record)

我应该用什么来替换这个???????????使用?

调用
handleError
时,记录器中没有错误,处理程序的
emit()
方法中有错误。同一个处理程序可以附加到任意数量的记录器,甚至可能不附加到最初接收日志的记录器,而是附加到日志层次结构中的任何其祖先

要获取生成处理程序出错日志的记录器的名称,可以访问对象的
name
属性。要获取实际的记录器对象,可以使用名称。因此,要将其填入代码中:

def handleError(self,record):
日志记录器\u表明\u有\u错误=record.name
#或者,如果需要记录器对象:
#logger\u that\u有\u错误=logging.getLogger(record.name)