Python 未设置记录器级别

Python 未设置记录器级别,python,logging,Python,Logging,我正在尝试从简单的打印切换到正确的日志记录 我想使用两个不同的记录器,第一个在屏幕上显示信息,另一个在文件中 我的问题是,即使我将我的处理程序级别设置为DEBUG,也只会从警告中显示消息 以下是我的代码示例: def setup_logger(self): """ Configures our logger to save error messages """ # create logger for 'facemovie' self.my_lo

我正在尝试从简单的打印切换到正确的日志记录

我想使用两个不同的记录器,第一个在屏幕上显示信息,另一个在文件中

我的问题是,即使我将我的处理程序级别设置为DEBUG,也只会从警告中显示消息

以下是我的代码示例:

def setup_logger(self):

    """

    Configures our logger to save error messages

    """

    # create logger for  'facemovie'

    self.my_logger = logging.getLogger('FileLog')

    # create file handler which logs even debug messages

    fh = logging.FileHandler('log/fm.log')

    fh.setLevel(logging.DEBUG)

    # create console handler with a higher log level

    self.console_logger = logging.getLogger('ConsoleLog')

    ch = logging.StreamHandler()

    ch.setLevel(logging.DEBUG)



    # create formatter and add it to the handlers

    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    fh.setFormatter(formatter)

    #ch.setFormatter(formatter)



    ##Start logging in file

    self.my_logger.info("######")



    # add the handlers to the logger

    self.my_logger.addHandler(fh)

    self.console_logger.addHandler(ch)



    # DEBUG

    self.console_logger.info("MFCKR")

    self.console_logger.debug("MFCKR")

    self.console_logger.warning("MFCKR")

    self.console_logger.error("MFCKR")

    self.console_logger.critical("MFCKR")

    self.my_logger.info("MFCKR")

    self.my_logger.debug("MFCKR")

    self.my_logger.warning("MFCKR")

    self.my_logger.error("MFCKR")

    self.my_logger.critical("MFCKR")
以及输出:

[jll@jll-VirtualBox:~/Documents/FaceMovie]$ python Facemoviefier.py -i data/inputs/samples -o data/
Selected profile is : frontal_face
MFCKR
MFCKR
MFCKR
Starting Application !
Output #0, avi, to 'data/output.avi':
    Stream #0.0: Video: mpeg4, yuv420p, 652x498, q=2-31, 20780 kb/s, 90k tbn, 5 tbc
FaceMovie exited successfully!
[jll@jll-VirtualBox:~/Documents/FaceMovie]$ cat log/fm.log 
2012-07-15 22:23:24,303 - FileLog - WARNING - MFCKR
2012-07-15 22:23:24,303 - FileLog - ERROR - MFCKR
2012-07-15 22:23:24,303 - FileLog - CRITICAL - MFCKR
我刷新了文档并在网上搜索了类似的错误,但没有找到任何错误

您是否知道记录器不显示调试和信息的原因

谢谢

不知道为什么我以前没找到它

必须设置整个日志记录器级别,即使处理程序也已设置。 我没有设置记录器的级别,我猜在这种情况下默认值是警告


问题解决了

通常的方法是设置记录器级别,并且仅在需要时设置处理程序级别。记录器级别控制从应用程序生成事件,而处理程序级别充当特定受众(例如开发人员、最终用户)的过滤器。我一定错过了阅读文档的机会。另一个问题让我明白了。顺便说一句,我真的很高兴(甚至可以说很荣幸)你花时间发表评论:)。非常感谢。