logging.ini日志配置文件内容示例:
 [loggers]
keys=root,demo [handlers]
keys=consoleHandler,timedRotatingFileHandler [formatters]
keys=simpleFmt [logger_root]
level=DEBUG
handlers=consoleHandler [logger_demo]
level=DEBUG
handlers=timedRotatingFileHandler
qualname=demo
propagate=0 [handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFmt
args=(sys.stdout,) [handler_timedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=simpleFmt
args=("demo.log", "d", 1, 0) [formatter_simpleFmt]
format=%(asctime)s - %(name)s - [%(filename)s:%(lineno)s]- %(levelname)s - %(message)s
datefmt=

使用示例:

 import logging
import logging.config logging.config.fileconfig("logging.ini")
logger = logging.getLogger("demo") if __name__ == "__main__":
logger.debug('This is debug message')
logger.info('This is info message')
logger.error('This is error message')

demo.log日志文件示例:

 2018-10-16 21:40:27,104 - demo - [log_record.py:15]- DEBUG - This is debug message
2018-10-16 21:40:27,105 - demo - [log_record.py:16]- INFO - This is info message
2018-10-16 21:40:27,105 - demo - [log_record.py:17]- ERROR - This is error message
 

Python示例-Logging的更多相关文章

  1. python模块 ---logging模块

    摘要by crazyhacking: 与log4cxx一样,分为三个部分,logger, handler,formatter. 详细内容参考:1官网http://docs.python.org/2/h ...

  2. 【python】logging日志模块写入中文编码错误解决办法

    一.问题: 使用python的logging模块记录日志,有时会遇到中文编码问题错误. 二.解决办法: 在logging.FileHandler(path) 中添加指定编码方式 encoding='u ...

  3. Python中logging模块的基本用法

    在 PyCon 2018 上,Mario Corchero 介绍了在开发过程中如何更方便轻松地记录日志的流程. 整个演讲的内容包括: 为什么日志记录非常重要 日志记录的流程是怎样的 怎样来进行日志记录 ...

  4. 转 使用Python的logging.config.fileConfig配置日志

    Python的logging.config.fileConfig方式配置日志,通过解析conf配置文件实现.文件 logglogging.conf 配置如下: [loggers]keys=root,f ...

  5. python之 logging 模块(上篇)

    一.日志关概念 日志是一种可以追踪某些软件运行时所发生事件的方法.软件开发人员可以向他们的代码中调用日志记录相关的方法来表明发生了某些事情.一个事件可以用一个可包含可选变量数据的消息来描述.此外,事件 ...

  6. Python之logging模块

    一.引言 之前在写一些小程序的时候想把日志内容打到文件中,所以就自己写了一个logger.py的程序,如下: #!/usr/bin/python # -*- coding=utf-8 -*- impo ...

  7. python的logging模块

    python提供了一个日志处理的模块,那就是logging 导入logging模块使用以下命令: import logging logging模块的用法: 1.简单的将日志打印到屏幕上 import ...

  8. python 多进程 logging:ConcurrentLogHandler

    python 多进程 logging:ConcurrentLogHandler python的logging模块RotatingFileHandler仅仅是线程安全的,如果多进程多线程使用,推荐 Co ...

  9. python的logging模块之读取yaml配置文件。

    python的logging模块是用来记录应用程序的日志的.关于logging模块的介绍,我这里不赘述,请参见其他资料.这里主要讲讲如何来读取yaml配置文件进行定制化的日志输出. python要读取 ...

随机推荐

  1. 校内题目T2691 桶哥的问题——送桶

    这是一道校内题目,但迷路的蒟蒻们同样被欢迎来此学习QWQ 题目描述: 题目背景 @桶哥本校——皎月pks大佬OrzOrz 买完了桶,桶哥要去送桶. 题目描述 桶哥买了nn个桶, 他要将这些桶送去nn个 ...

  2. inoutfy与rsync进行实时同步

    更新阿里epel源 安装镜像源 curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo --- 扩展 ...

  3. 怎么画一条0.5px的边

    编者按:本文由人人网FED发表于掘金,并已授权奇舞周刊转载 什么是像素? 像素是屏幕显示最小的单位,在一个1080p的屏幕上,它的像素数量是1920 1080,即横边有1920个像素,而竖边为1080 ...

  4. percon server5.7的配置版本

    percon server5.7的配置版本 [root@tidb-db-backup mysql_3306]# cat my_3306.cnf # my_3306.cnf [client] port ...

  5. Python条件控制与循环

    条件控制语句:if 循环语句:while.for 其他语句:continue.break.pass 1.if语句 # ================================ a = 1 if ...

  6. linux-awk-3

    awk 基础语法 Awk –Fs '/pattern/ {action}' input-file (或者) Awk –Fs '{action}' input-file -F 为字段分界符.如果不指定, ...

  7. BZOJ 3786: 星系探索 ETT

    Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球均有且仅有一个依赖星球.主星球 ...

  8. 2018百度之星B轮 degree

    degree Accepts: 1581 Submissions: 3494 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/1 ...

  9. HDU 2612 Find a way(双向bfs)

    题目代号:HDU 2612 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 Find a way Time Limit: 3000/1000 M ...

  10. (62)通信协议之一protobuf

     Protobuf协议特点分析 KingKa.吴永聪 1.protobuf是什么? protobuf(Google Protocol Buffers)是Google提供的一个具有高效的协议数据交换格式 ...