这是来自源代码的示例代码:https://docs.python.org/3/howto/logging.html
import logging\nlogging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)\nlogging.debug('This message should go to the log file')\nlogging.info('So should this')\nlogging.warning('And this, too')\nlogging.error('And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6')\n
Run Code Online (Sandbox Code Playgroud)\n我认为level=logging.DEBUG
下面的代码
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)\n
Run Code Online (Sandbox Code Playgroud)\nlogging
只接受logging.DEBUG
。那为什么info
,,warning
工作error
小智 5
python的日志记录级别按以下顺序排列:
\n如果您在配置时将根日志记录器级别设置为logging.DEBUG
,它将写入高于该级别的所有日志。
例子:
\nimport logging\nlogging.basicConfig(filename=\'example.log\', encoding=\'utf-8\', level=logging.DEBUG)\nlogging.debug(\'This message should go to the log file\')\nlogging.info(\'So should this\')\nlogging.warning(\'And this, too\')\nlogging.error(\'And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6\')\n
Run Code Online (Sandbox Code Playgroud)\n输出:
\nDEBUG:root:This message should go to the log file\nINFO:root:So should this\nWARNING:root:And this, too\nERROR:root:And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6\n
Run Code Online (Sandbox Code Playgroud)\n如果您在配置时将根记录器级别设置为logging.ERROR
,它将仅写入 CRITICAL 日志和 ERROR 日志。
例子:
\nDEBUG:root:This message should go to the log file\nINFO:root:So should this\nWARNING:root:And this, too\nERROR:root:And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6\n
Run Code Online (Sandbox Code Playgroud)\n输出:
\nERROR:root:And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6\nCRITICAL:root:And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6 2\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
1366 次 |
最近记录: |