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. zz深度学习中的注意力模型

    中间表示: C -> C1.C2.C3 i:target -> IT j: source -> JS sim(Query, Key) -> Value Key:h_j,类似某种 ...

  2. 读架构漫谈&我眼中的架构师

    本周是开学的第二周,读了由资深架构师王概凯 Kevin 执笔的系列专栏架构漫谈.初识这门课,懂得也不是很多,读了架构漫谈,有了一些理解. 首先作者讲述了缘起,由早期人独立自主生活到后来的集群,作者由这 ...

  3. C++——二维vector初始化大小方法

    初始化二维vector,为r*c的vector,所有值为0.1.直接用初始化方法(刚开始没想到) vector<vector<int> > newOne(r, vector&l ...

  4. 树莓派autossh反向隧道

    本来我是将树莓派连接到路由器,从而在电脑端通过IP访问.远在局域网之外的队友怎么访问呢? ssh反向隧道 它的原理比较简单: 树莓派主动向某公网服务器建立ssh连接,并请求公网服务器开启一个额外的SS ...

  5. github新建本地仓库并将代码提交到远程仓库

    方式一: 在github上新建好仓库:gitTest 使用命令git clone git@github.com:yourgithubID/gitTest.git,克隆到本地相应的位置 将要上传的工程代 ...

  6. chrome 模拟发送请求的方法

    chrome f12 看到了web页面的请求,有时候想修改一下参数重新执行一下怎么办? 如果是get方法.参数不多可以直接在浏览器中打开.否则post方法参数多时很多人会复制到postman中执行,但 ...

  7. [LeetCode] 30. Substring with Concatenation of All Words 串联所有单词的子串

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

  8. [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合

    Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...

  9. Python-lambda使用

    什么是lambda 匿名函数,不需要命名的函数: 语法 lambda 参数 : 返回值 g = lambda x: 2*x+1 g(2) >5

  10. 关于App收集个人信息基本规范,这里公开征求你的意见!

    关于App收集个人信息基本规范,这里公开征求你的意见! https://www.thepaper.cn/newsDetail_forward_4122573 以后国家开始规范App收集个信息基本规范, ...