python的logging
来源:互联网 发布:linux shell启动jar包 编辑:程序博客网 时间:2024/06/05 10:00
平时写代码的时候一般都是通过IDE的debug调试输出,这种方法对于一些小程序很好,方便,快捷。
然而在python中可以用logging来实现。而且logging直接输入到,文件或者控制台上,最主要还是loging
创建一个logger后,这个logger是一个全局量,所以使用起来,大家都懂的。
下面是两种常用的logger。一种是写文件上,一种是写terminal上。
import loggingimport sysif __name__ == "__main__": loglevel=logging.DEBUG formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') stdout_handler = logging.StreamHandler(sys.stderr) stdout_handler.setFormatter(formatter) file_handler = logging.FileHandler("file.log") file_handler.setFormatter(formatter) logging.getLogger("File").setLevel(loglevel) logging.getLogger("File").addHandler(file_handler) logging.getLogger(__name__).setLevel(loglevel) logging.getLogger(__name__).addHandler(stdout_handler) fileLoger=logging.getLogger("File") stdLoger=logging.getLogger(__name__) fileLoger.error("hello") fileLoger.error("world") stdLoger.debug("std") stdLoger.debug("output")
0 0
- python的logging库
- python的logging模块
- python的logging模块
- python 的logging
- python的logging
- python 的 logging 模块
- python logging的学习
- Python 的Logging模块
- Python的logging
- python 的logging模块
- python的logging使用
- Python的logging使用
- python的logging类
- python logging的使用
- python 的logging模块
- 使用Python的logging.config
- python的日志工具logging
- Python的标准logging模块
- 整数1到100的和
- sqlserver 数据库无法用127.0.0.1 连接本机数据库的问题
- Python文件夹与文件的操作
- 解决Android SDK Manager 更新、下载慢以及待安装包列表不显示的问题
- EasyUI弹出框,随滚动条移动 弹出图片预览自动缩略
- python的logging
- Android学习笔记__2__Android工程目录结构
- org.apache.log4j.Logger 详解
- 文件与二进制数据互转-ByteArrayOutputStream
- 王立平--eclipse中Ctrl+Shift+F格式化代码快捷键不管用了?
- 构建struts2框架的基本方法
- 定制Linux发行版:向CentOS6安装镜像添加自定义软件包
- 实现自己的LUA绑定器-一个模板编程挑战
- Python stat 模块