美文网首页
Python 日志的学习

Python 日志的学习

作者: 潘雪雯 | 来源:发表于2021-02-09 18:15 被阅读0次

    Python自带的有logging模块

    import logging
    logging.basicConfig(level=logging.DEBUG,  # 控制台打印的日志级别
                        filename=pwd + '/log.log',
                        filemode='a',  ##追加模式
                        # a是追加模式,默认如果不写的话,就是追加模式
                        format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'  # 日志格式
                        )
    

    在文件的开头设置完成后,就可以在需要打印日志的地方加入如下语句:

    logging.error("error message   error_xxx:" + str(xxxx))
    

    相关文章

      网友评论

          本文标题:Python 日志的学习

          本文链接:https://www.haomeiwen.com/subject/djscxltx.html