131、logging 模块:记录日志
本文最后更新于 68 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com

logging 模块:记录日志

logging 模块可以用来记录日志:

import logging

logging 的日志类型有以下几种:

  • logging.critical(msg)
  • logging.error(msg)
  • logging.warning(msg)
  • logging.info(msg)
  • logging.debug(msg)

级别排序为:CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET

默认情况下,logging 的日志级别为 WARNING,只有不低于 WARNING 级别的日志才会显示在命令行。

logging.critical('This is critical message')
logging.error('This is error message')
logging.warning('This is warning message')

# 不会显示
logging.info('This is info message')
logging.debug('This is debug message')
CRITICAL:root:This is critical message
ERROR:root:This is error message
WARNING:root:This is warning message

可以这样修改默认的日志级别:

logging.root.setLevel(level=logging.INFO)

logging.info('This is info message')
INFO:root:This is info message

可以通过 logging.basicConfig() 函数来改变默认的日志显示方式:

logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s')

logger = logging.getLogger("this program")

logger.critical('This is critical message')
CRITICAL:this program:This is critical message
谨此笔记,记录过往。凭君阅览,如能收益,莫大奢望。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇