logging模块使用
日志介绍
日志级别:
默认显示级别为warning,(critical>error>warning>info>debug>notset)
日志格式配置,测试使用
import logging
logging.basicConfig(
level=logging.DEBUG,
filename = "logger.log",
# filemode="w", #以写入覆盖的方式添加内容,默认以追加方式
format = "[%(lineno)d] %(asctime)s %(levelname)s '%(message)s'"
)
logging.debug('debug message')
logging.info('info message')
logging.warning('warning message')
logging.error('error message')
logging.critical('critical message')
日志格式配置
import logging
def set_logger():
logger = logging.getLogger() #创建logger对象o
fileh = logging.FileHandler("test.log") #向文件test.log发送日志
strh = logging.StreamHandler() #向屏幕发送日志
# fm = logging.Formatter("%(lineno)s %(asctime)s %(message)s")
fm = logging.Formatter("%(asctime)s %(filename)s[%(lineno)d] %(levelname)s '%(message)s'")
fileh.setFormatter(fm) #将日志格式添加到fileh
strh.setFormatter(fm) #将日志格式添加到strh
logger.addHandler(fileh) #添加文件handler
logger.addHandler(strh) #添加屏幕handler
logger.setLevel("DEBUG") #设置日志默认级别为debug
return logger
#其他函数调用要使用logger对象
import xxx
logger = set_logger()
logger.debug("xxx")
logging模块使用的更多相关文章
- Python Logging模块的简单使用
前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...
- logging 模块误用导致的内存泄露
首先介绍下怎么发现的吧, 线上的项目日志是通过 logging 模块打到 syslog 里, 跑了一段时间后发现 syslog 的 UDP 连接超过了 8W, 没错是 8 W. 主要是 logging ...
- python logging模块详解[转]
一.简单将日志打印到屏幕: import logging logging.debug('debug message') logging.info('info message') logging.war ...
- python logging模块
1.logging模块提供了四个组件logger:日志类,有两个功能1)配置日志的等级,处理器handler,过滤器filterlogger.setLevel(logging.INFO)logger. ...
- python logging模块可能会令人困惑的地方
python logging模块主要是python提供的通用日志系统,使用的方法其实挺简单的,这块就不多介绍.下面主要会讲到在使用python logging模块的时候,涉及到多个python文件的调 ...
- Python之logging模块
一.引言 之前在写一些小程序的时候想把日志内容打到文件中,所以就自己写了一个logger.py的程序,如下: #!/usr/bin/python # -*- coding=utf-8 -*- impo ...
- logging模块转载博客
转载自:http://blog.csdn.net/zyz511919766/article/details/25136485 简单将日志打印到屏幕: [python] view plain copy ...
- Python中的logging模块
http://python.jobbole.com/86887/ 最近修改了项目里的logging相关功能,用到了python标准库里的logging模块,在此做一些记录.主要是从官方文档和stack ...
- Python中的日志管理Logging模块
1.基本的用法 import logging logging.debug('This is debug message') logging.info('This is info message') l ...
- Python日志输出——logging模块
Python日志输出——logging模块 标签: loggingpythonimportmodulelog4j 2012-03-06 00:18 31605人阅读 评论(8) 收藏 举报 分类: P ...
随机推荐
- https://github.com/tensorflow/models/blob/master/research/slim/datasets/preprocess_imagenet_validation_data.py 改编版
#!/usr/bin/env python # Copyright 2016 Google Inc. All Rights Reserved. # # Licensed under the Apach ...
- 2018-2019-1 20189203《Linux内核原理与分析》第三周作业
一.课程学习 计算机的三个法宝:存储程序计算机.函数调用堆栈.中断. 堆栈相关的寄存器:ESP(堆栈指针).EBP(基址指针). 堆栈操作:push:栈顶地址减少4个字节,并将操作数放入栈顶存储单元. ...
- SpringMVC 图片上传,检查图片大小
使用SpringMVC+Spring 前端提交图片文件到Controller,检查上传图片大小是否符合要求 直接上代码了 1.校验图片大小 这里提供出验证的方法,用于在需要校验的地方调用 /** * ...
- qemu-kvm内存虚拟化2
2017-04-20 上篇文章对qemu部分的内存虚拟化做了介绍,上篇文章对于要添加的FR,调用了 MEMORY_LISTENER_UPDATE_REGION(frnew, as, Forward, ...
- week_one-python基础 列表 增删改查
# Author:larlly #列表增删改查#定义列表name = ["wo","ni","ta","wo"] #定义 ...
- wm_concat函数oracle 11g返回clob
用wm_concat连接拼接字符串,测试环境是10g,一切正常 到了生产环境是11g,点开直接报错了 wm_concat函数在oracle 10g返回的是字符串,到了11g返回的是clob 解决办法: ...
- Python xml模块
xml模块 自己创建xml文档 import xml.etree.cElementTree as ET new_xml = ET.Element("personinfolist") ...
- mongodb集群配置及备份恢复
Mongodb安装: 编辑/etc/yum.repos.d/mongodb.repo,添加以下: [MongoDB] name=MongoDB Repository baseurl=https://r ...
- msf下的各种生成payload命令
Often one of the most useful (and to the beginner underrated) abilities of Metasploit is the msfpayl ...
- Bootstrap3基础 text-right/left/center 设置标题右对齐、左对齐、居中
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...