`
crazier9527
  • 浏览: 995113 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Python的标准logging模块(2)

阅读更多

Formatters

Formatter objects configure the final order, structure, and contents of the log message. Unlike the base logging.Handler class, application code may instantiate formatter classes, although you could likely subclass the formatter if your application needs special behavior. The constructor takes two optional arguments: a message format string and a date format string. If there is no message format string, the default is to use the raw message. If there is no date format string, the default date format is:

Formatter对象定义了最终log信息的顺序,结构和内容.于基本的logging.Handler类不同,应用可以直接实例化formatter,当然,如果需要你也可以子例化formatter以便定制它的一些行为.构造函数接受两个可选参数:一个信息格式字符串和一个日期格式字符串.如果没有信息格式字符串,直接输出log信息.如果没有日期格式字符串,默认的格式是:

%Y-%m-%d %H:%M:%S

with the milliseconds tacked on at the end.

毫秒加载最后面.

The message format string uses %(<dictionary key>)s styled string substitution. Here is the Formatter class's docstring, which describes the valid substitution strings and what they mean:

信息格式字符串用%(<dictionary key>)s风格的字符串做替换.下面是Formatter类的docstring,说明了现有的替换字符串和它们所代表的意思.

%(name)s            Name of the logger (logging channel)

%(levelno)s         Numeric logging level for the message (DEBUG, INFO,

                    WARNING, ERROR, CRITICAL)

%(levelname)s       Text logging level for the message ("DEBUG", "INFO",

                    "WARNING", "ERROR", "CRITICAL")

%(pathname)s        Full pathname of the source file where the logging

                    call was issued (if available)

%(filename)s        Filename portion of pathname

%(module)s          Module (name portion of filename)

%(lineno)d          Source line number where the logging call was issued

                    (if available)

%(created)f         Time when the LogRecord was created (time.time()

                    return value)

%(asctime)s         Textual time when the LogRecord was created

%(msecs)d           Millisecond portion of the creation time

%(relativeCreated)d Time in milliseconds when the LogRecord was created,

                    relative to the time the logging module was loaded

                    (typically at application startup time)

%(thread)d          Thread ID (if available)

%(process)d         Process ID (if available)

%(message)s         The result of record.getMessage(), computed just as

                    the record is emitted

The following message format string will log the time in a human-readable format, the severity of the message, and the contents of the message, in that order:

下面的信息格式字符串会输出一个可读格式的串,严重级别和log信息内容以下面的格式给出:

"%(asctime)s - %(levelname)s - %(message)s"

分享到:
评论

相关推荐

    python的logging模块

    用python写程序的,作为一个完整的项目而言,必须要有日志模块,而python的logging模块为我们提供了这么一种很好的机制,很方便的解决了这个问题。

    python的logging模块.pdf

    详解python的日志模块logging和django中对logging模块的使用

    python logging 模块

    logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级、日志保存路径、日志文件回滚等;相比print,具备如下优点: 可以通过设置不同的日志等级,在release版本中只输出重要信息,而...

    python中logging模块

    转载于https://www.cnblogs.com/Nicholas0707/p/9021672.html,支持正版

    详解Python中logging日志模块在多进程环境下的使用

    许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行...这篇文章给大家主要介绍了在Python中logging日志模块在多进程环境下的使用,需要的朋友可以参考借鉴,下面来一起看看吧。

    python 日志 logging模块详细解析

    主要介绍了python 日志 logging模块 详细解析,本文通过实例代码给大家介绍的非常详细,对大家的工作或学习具有一定的参考借鉴价值,需要的朋友可以参考下

    Python使用logging模块实现打印log到指定文件的方法

    主要介绍了Python使用logging模块实现打印log到指定文件的方法,结合实例形式分析了Python logging模块的原理及相关日志输出操作技巧,需要的朋友可以参考下

    Python日志logging模块功能与用法详解

    本文实例讲述了Python日志logging模块功能与用法。分享给大家供大家参考,具体如下: 本文内容: logging模块的介绍 logging模块的基础使用 logging模块的扩展使用 logging中的Filter 使用配置文件配置logging...

    详解使用python的logging模块在stdout输出的两种方法

     使用python的logging模块时,除了想将日志记录在文件中外,还希望在前台执行python脚本时,可以将日志直接输出到标准输出std.out中。 实现  logging模块可以有两种方法实现该功能: 方案一:basicconfig import ...

    Python logging模块handlers用法详解

    主要介绍了Python logging模块handlers用法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

    Python中内置的日志模块logging用法详解

    Python的logging模块提供了通用的日志系统,可以方便第三方模块或者是应用使用。这个模块提供不同的日志级别,并可以采用不同的方式记录日志,比如文件,HTTP GET/POST,SMTP,Socket等,甚至可以自己实现具体的日志...

    python日志logging模块使用方法分析

    本文实例讲述了python日志logging模块使用方法。分享给大家供大家参考,具体如下: 一、从一个使用场景开始 开发一个日志系统, 既要把日志输出到控制台, 还要写入日志文件 import logging # 创建一个logger ...

    python使用logging模块发送邮件代码示例

    主要介绍了python使用logging模块发送邮件代码示例,具有一定借鉴价值,需要的朋友可以参考下

    python logging日志模块以及多进程日志详解

    python的logging模块提供了灵活的标准模块,使得任何Python程序都可以使用这个第三方模块来实现日志记录。python logging 官方文档 logging框架中主要由四个部分组成: Loggers: 可供程序直接调用的接口 Handlers:...

    解读python logging模块的使用方法

    logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级、日志保存路径、日志文件回滚等;相比print,具备如下优点: 1.可以通过设置不同的日志等级,在release版本中只输出重要信息,...

    Python logging模块原理解析及应用

    主要介绍了Python logging模块原理解析及应用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics