由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 本周Python module 学习:logging (日志记录)
相关主题
实在搞不懂Rcpp有啥好处[急求助] survival analysis (SAS)
求教:R里面怎么屏蔽一个子程序打印到屏幕的输出?update (some interview experiences)--急,面试求助:用ACCESS
【包子】从excel读取数据到R的问题Propensity score or Instrumental Variable?
求书probability and statistics by degroot 第三版或者第四版c++的compile和debug是不是不是一回事?
[求助]R程序run着run着就自己killed了,可能是什么原因?Numpy problem
How to run my R job as a batch job ?请教一个SIMULATION的问题
[合集] SAS 程序 Editor 窗口显示 在 running,实际上是死了,请教转载:浅谈一些base更新题库后的考证情况
考完Base SAS,汇报一下请大家谈谈对于risk analyst工作的看法好吗
相关话题的讨论汇总
话题: 日志话题: logging话题: api话题: 记录话题: messages
进入Statistics版参与讨论
1 (共1页)
S******y
发帖数: 1123
1
许多应用程序中都会有日志记录,用于记录系统在运行过程中的一些关键信息,以便于
对系统的运行状况进行跟踪。python为我们提供了简单易用、且功能强大的日志模块:
logging
The logging module defines a standard API for reporting errors and status
information from applications and libraries. The key benefit of having the
logging API provided by a standard library module is that all Python modules
can participate in logging, so an application’s log can include messages
from third-party modules.
logging模块支持将日志信息保存,如:保存到日志文件中;以邮件的形式发送日志信
息;以http get或post的方式提交日志到web服务器;等等。
举一个简单的例子:
import logging
logging.basicConfig(filename = os.path.join(os.getcwd(), 'log.txt'), level =
logging.DEBUG)
logging.debug('this is a message')
运行上面例子的代码,将会在程序的根目录下创建一个log.txt文件,打开该文件,里
面有一条日志记录:”DEBUG:root:this is a message”。
Verbosity Levels
Another useful feature of the logging API is the ability to produce
different messages at different log levels. This code to be instrumented
with debug messages, for example, while setting the log level down so that
those debug messages are not written on a production system.
--------------------
logger: 日志类,应用程序往往通过调用它提供的api来记录日志;
handler: 对日志信息处理,可以将日志发送(保存)到不同的目标域中;
filter: 对日志信息进行过滤;
formatter:日志的格式化;
-----------------------
详见 -
https://pymotw.com/2/logging/
http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python
1 (共1页)
进入Statistics版参与讨论
相关主题
请大家谈谈对于risk analyst工作的看法好吗[求助]R程序run着run着就自己killed了,可能是什么原因?
请教各位大牛 R 在 PC/MAC 运行的问题How to run my R job as a batch job ?
[合集] 读大数据文件的时候遇到的问题[合集] SAS 程序 Editor 窗口显示 在 running,实际上是死了,请教
statistical genetics summer school in UW考完Base SAS,汇报一下
实在搞不懂Rcpp有啥好处[急求助] survival analysis (SAS)
求教:R里面怎么屏蔽一个子程序打印到屏幕的输出?update (some interview experiences)--急,面试求助:用ACCESS
【包子】从excel读取数据到R的问题Propensity score or Instrumental Variable?
求书probability and statistics by degroot 第三版或者第四版c++的compile和debug是不是不是一回事?
相关话题的讨论汇总
话题: 日志话题: logging话题: api话题: 记录话题: messages