• python中的日志级别


    python中的日志级别

    Python按照重要程度把日志分为5个级别,如下:

    可以通过level参数,设置不同的日志级别。当设置为高的日志级别时,低于此级别的日志不再打印。

    五种日志级别按从低到高排序:

    DEBUG < INFO < WARNING < ERROR < CRITICAL

    1. level设置为DEBUG级别,所有的日志都会打印

    import logging
    logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s -%(message)s')
    logging.debug('Some debugging details.')
    logging.info('The logging module is working')
    logging.warning('An error message is about to be logged.')
    logging.error('An error has occurred.')
    logging.critical('The program is unable to recover!')
    
     2019-11-17 15:24:30,065 - DEBUG -Some debugging details.
     2019-11-17 15:24:30,074 - INFO -The logging module is working
     2019-11-17 15:24:30,086 - WARNING -An error message is about to be logged.
     2019-11-17 15:24:30,105 - ERROR -An error has occurred.
     2019-11-17 15:24:30,107 - CRITICAL -The program is unable to recover!
    
    
    1. level设置为ERROR级别时,只显示ERROR和CRITICAL日志

    import logging
    logging.basicConfig(level=logging.ERROR, format=' %(asctime)s - %(levelname)s -%(message)s')
    logging.debug('Some debugging details.')
    logging.info('The logging module is working')
    logging.warning('An error message is about to be logged.')
    logging.error('An error has occurred.')
    logging.critical('The program is unable to recover!')
    
     2019-11-17 15:30:46,767 - ERROR -An error has occurred.
     2019-11-17 15:30:46,768 - CRITICAL -The program is unable to recover!
    
  • 相关阅读:
    关于DataGrid最后一页只有一行记录时,删除此记录出错的问题
    数据库开发个人总结(ADO.NET小结)
    MSSQL server数据库开发精典技巧
    愈强愈勇(奥运六星)
    中国与日本的生活对比 转)
    古龙妙语录
    DataGrid单击行时改变颜色
    VS.NET 2003 控件命名规范
    qt国际化
    Histogram matching using python, opencv
  • 原文地址:https://www.cnblogs.com/wwbplus/p/12001788.html
Copyright © 2020-2023  润新知