# !/user/bin/python
# -*- coding: utf-8 -*-
'''
subprocess : 需要在linux平台上测试 shell
logging
''' import logging
# 将日志输出在文件里
# logging.basicConfig(filename="app.log", level=logging.DEBUG)
logging.basicConfig(filename="app.log",
level=logging.WARNING,
format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p') # 在日志上加上时间. %p代表pm. TODO 为什么没打出行数?
logging.debug("test debug")
logging.info("test info")
logging.error("test error")
logging.warning("User [alex] attempted wrong password more than 3 times") # 同时将日志打印在屏幕上并输出在文件里
# step 1, create logger
logger = logging.getLogger("TEST-LOG")
logger.setLevel(logging.DEBUG) # step2, create console handler and set level to debug
ch=logging.StreamHandler()
ch.setLevel(logging.DEBUG) # step3, create file handler and set level to warning
fh = logging.FileHandler("process.log")
fh.setLevel(logging.ERROR) # step3, define format
fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s')
ch_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(fh_formatter)
ch.setFormatter(ch_formatter) # step4, connect handlers to logger
logger.addHandler(fh)
logger.addHandler(ch) logger.warning("ddddd")
Level When it’s used
DEBUG Detailed information, typically of interest only when diagnosing problems.
INFO Confirmation that things are working as expected.
WARNING An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.
ERROR Due to a more serious problem, the software has not been able to perform some function.
CRITICAL A serious error, indicating that the program itself may be unable to continue running.

Python logger /logging的更多相关文章

  1. [Python 模块] logging模块、Logger类

    logging模块: 标准库里面的logging模块,在前面学习线程安全时曾用来解决print被打断的问题,这里会介绍logging模块的功能. logging模块是线程安全的,不需要客户做任何特殊的 ...

  2. Python日志logging

    logging 用于便捷记录日志且线程安全的模块 1.单文件日志 import logging logging.basicConfig(filename='log.log', format='%(as ...

  3. Python之logging模块

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

  4. python 记录日志logging

    在项目开发中,往往要记录日志文件.用python记录日志有两种方式: 1.利用python 自带的logging库,例如: # -*- coding: utf-8 -*- import osimpor ...

  5. python模块 ---logging模块

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

  6. python的logging模块

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

  7. python 多进程 logging:ConcurrentLogHandler

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

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

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

  9. Python:logging 的巧妙设计

    引言 logging 的基本用法网上很多,这里就不介绍了.在引入正文之前,先来看一个需求: 假设需要将某功能封装成类库供他人使用,如何处理类库中的日志? 数年前在一个 C# 开发的项目中,我用了这样的 ...

随机推荐

  1. 如何获取自己想要模拟的APP的相关图片?

    一.首先打开iTunes APP,找到自己想要模拟实现的APP,并下载 二.找到下载的APP在iTunes中的位置 三.选中对应的APP,点击右键选择在Finder中显示,会打开对应的文件窗口,打开对 ...

  2. listview中的adapter学习小结

    概述 Adapter是数据和UI之间的一个桥梁,在listview,gridview等控件中都会使用到,android给我们提拱了4个adapte供我们使用: BaseAdapter是一个抽象类,继承 ...

  3. 关于ARC的介绍和ARC与MRC混编解决

    1. ARC & MRC 混合开发 在项目开发中,遇到使用MRC开发的第三方库怎么办? 例如:ASI 1> 尝试使用Xcode的转换工具(失败率比较高) 2> 在编译选项中,为MR ...

  4. 和菜鸟一起学linux之DBUS基础学习记录

    D-Bus三层架构 D-Bus是一个为应用程序间通信的消息总线系统, 用于进程之间的通信.它是个3层架构的IPC 系统,包括: 1.函数库libdbus ,用于两个应用程序互相联系和交互消息. 2.一 ...

  5. Error filterStart的问题

    今天出现这个问题 严重: Error filterStart org.apache.catalina.core.StandardContext start 严重: Context startup fa ...

  6. merge intervals(合并间隔)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  7. Memcache架构新思考

    2011年初Marc Kwiatkowski通过Memecache@Facebook介绍了Facebook的Memcache架构,现在重新审视这个架构,仍有很多方面在业界保持先进性.作为weibo内部 ...

  8. H5之postMessage 。实现跨域

    对于跨域我们有很多的解决方案,今天我来分享一下postMessage的那点事,postMessage是html5新增的一个解决跨域的一个方法,不过很可惜万恶的ie6,7不支持 postMessage( ...

  9. Visual Studio Community 2013,功能完整,免费使用

    http://www.infoq.com/cn/news/2014/11/VSC2013 微软刚刚宣布了.NET平台的开源计划,与此同时,它还推出了源自Visual Studio Profession ...

  10. vfd with stm8

    2018-01-14 22:50:26 之前写了pt6311的驱动,要做时钟考虑使用stm8做主控,于是乎将之前的驱动移植到stm8上. 顺带熟悉了stm8的操作2333. 上源码: #ifndef ...