logging模块之Formatter格式

在记录日志是,日志输出的格式也是非常重要的,无论对于开发调试阶段,还是运维阶段。Formater对象用于定制日志的输出格式,而格式有依赖于格式字符串,格式字符串是字典mapping类型。而格式化字符串中的关键字key其实是LogRecorder对象的属性。所以要学习日志的格式就要Formatter,格式化字符串,LogRecorder对象属性,以及时间格式化字符串。这4点掌握完就可以了。

Formater对象

参考《Python logging 模块》

日志输出格式化字符串

格式化字符串就是python的格式化字符串,不过是字典映射类型,key就是LogRecorder对象的属性。
默认是: '%(message)s' 只有消息内容。

LogRecoder对象

重要关注该对象的属性,用于格式化字符串中.
定义日志输出时作为参考,点击下面连接。
参考官档: 点击这里

https://docs.python.org/3.7/library/logging.html#logrecord-attributes

时间格式化字符串

默认就好,默认是:'%Y-%m-%d %H:%M:%S,uuu' 后面uuu代表毫秒值。

0x03 Python logging模块之Formatter格式的更多相关文章

  1. python logging模块可能会令人困惑的地方

    python logging模块主要是python提供的通用日志系统,使用的方法其实挺简单的,这块就不多介绍.下面主要会讲到在使用python logging模块的时候,涉及到多个python文件的调 ...

  2. python logging模块使用

    近来再弄一个小项目,已经到收尾阶段了.希望加入写log机制来增加程序出错后的判断分析.尝试使用了python logging模块. #-*- coding:utf-8 -*- import loggi ...

  3. (转)python logging模块

    python logging模块 原文:http://www.cnblogs.com/dahu-daqing/p/7040764.html 1 logging模块简介 logging模块是Python ...

  4. Python logging 模块学习

    logging example Level When it's used Numeric value DEBUG Detailed information, typically of interest ...

  5. python logging—模块

    python logging模块 python logging提供了标准的日志接口,python logging日志分为5个等级: debug(), info(), warning(), error( ...

  6. 0x01 Python logging模块

    目录 Python logging 模块 前言 logging模块提供的特性 logging模块的设计过程 logger的继承 logger在逻辑上的继承结构 logging.basicConfig( ...

  7. 读懂掌握 Python logging 模块源码 (附带一些 example)

    搜了一下自己的 Blog 一直缺乏一篇 Python logging 模块的深度使用的文章.其实这个模块非常常用,也有非常多的滥用.所以看看源码来详细记录一篇属于 logging 模块的文章. 整个 ...

  8. Python logging模块无法正常输出日志

    废话少说,先上代码 File:logger.conf [formatters] keys=default [formatter_default] format=%(asctime)s - %(name ...

  9. Python Logging模块的简单使用

    前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...

随机推荐

  1. 大宗商品市场的未来王者 | 现货贸易商PK期货风险管理子公司

    https://mp.weixin.qq.com/s/z-kkeIor6vDb9Oer73Ct6w 大宗商品市场卧虎藏龙,参与者众多,然而能称之为王者的却寥寥无几. 在国外,以嘉能可.托克.摩科瑞为代 ...

  2. Python进阶-VII 内置函数

    一.内置函数引入 我们已经了解的有; print()  input() range() next()  dir() str() int() list() set() tuple() dict() he ...

  3. openjdk11 stretch基础镜像无法找到对应openjdk dbg 包的问题

    今天在构建一个jdk perf 工具基于openjdk 11 发现8 的dbg 一直可以查找到,但是11的就是没有 参考issue https://github.com/docker-library/ ...

  4. [LeetCode] 915. Partition Array into Disjoint Intervals 分割数组为不相交的区间

    Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...

  5. [LeetCode] 85. Maximal Rectangle 最大矩形

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and ...

  6. [LeetCode] 214. Shortest Palindrome 最短回文串

    Given a string s, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  7. 第02组 Alpha冲刺(5/6)

    队名:無駄無駄 组长博客 作业博客 组员情况 张越洋 过去两天完成了哪些任务 摸鱼 准备"Alpha事后诸葛亮" 提交记录(全组共用) 接下来的计划 沟通前后端成员,监督.提醒他们 ...

  8. 微信小程序前端调用后台方法并获取返回值

    wxml代码 <wxs src="../../wxs/string.wxs" module="tools" /> <!-- 调用tools.i ...

  9. Java软件生产监控工具Btrace的使用

    Btrace BTrace是sun公司推出的一款Java 动态.安全追踪(监控)工具,可以在不用重启的情况下监控系统运行情况,方便的获取程序运行时的数据信息,如方法参数.返回值.全局变量和堆栈信息等, ...

  10. ABP vNext中使用开源日志面板 LogDashboard

    ABP vNext 使用 logdashboard 本文示例源码:https://github.com/liangshiw/LogDashboard/tree/master/samples/abpvn ...