import logging
logfile = 'e:\\a.txt'
# logging.basicConfig(filename=logfile,level=logging.INFO)
# logging.basicConfig(format='%(time.asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.basicConfig(level=logging.INFO,
#format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', #返回值:Thu, 26 May 2016 15:09:31 t11.py[line:92] INFO
format='%(asctime)s %(levelname)s %(message)s',
#datefmt='%a, %d %b %Y %H:%M:%S',
#datefmt='%Y/%m/%d %I:%M:%S %p', #返回2016/05/26 03:12:56 PM
datefmt='%Y-%m-%d %H:%M:%S', #返回2016/05/26 03:12:56 PM
filename=logfile#,
#filemode='a' #默认为a
) logging.info('username valid passed.\r') #logging会自动在每行log后面添加"\000"换行,windows下未自动换行 #logging输出结果:
#2016-05-26 15:22:29 INFO liu1 valid passed.
#2016-05-26 15:22:37 INFO liu1 valid passed.

参考:http://blog.chinaunix.net/uid-26000296-id-4372063.html

     http://www.cnblogs.com/alex3714/articles/5161349.html

日志级别等级:CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET

format参数中可能用到的格式化串:
%(name)s             Logger的名字
%(levelno)s          数字形式的日志级别
%(levelname)s     文本形式的日志级别
%(pathname)s     调用日志输出函数的模块的完整路径名,可能没有
%(filename)s        调用日志输出函数的模块的文件名
%(module)s          调用日志输出函数的模块名
%(funcName)s     调用日志输出函数的函数名
%(lineno)d           调用日志输出函数的语句所在的代码行
%(created)f          当前时间,用UNIX标准的表示时间的浮 点数表示
%(relativeCreated)d    输出日志信息时的,自Logger创建以 来的毫秒数
%(asctime)s                字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒
%(thread)d                 线程ID。可能没有
%(threadName)s        线程名。可能没有
%(process)d              进程ID。可能没有
%(message)s            用户输出的消息

参考链接:https://www.cnblogs.com/dreamer-fish/p/5460929.html

Python中日志的格式化输出的更多相关文章

  1. python 中的字符串格式化

    python 中的字符串格式化 %方式的调用 1.格式化代码 代码 意义 s 字符串,使用str r 字符串,使用repr不使用str c 字符 d 十进制的数字 i 整数 u 无符号整数 o 八进制 ...

  2. python中日志logging模块的性能及多进程详解

    python中日志logging模块的性能及多进程详解 使用Python来写后台任务时,时常需要使用输出日志来记录程序运行的状态,并在发生错误时将错误的详细信息保存下来,以别调试和分析.Python的 ...

  3. python学习笔记 | strftime()格式化输出时间

    time模块 import time t = time.strftime("%Y-%m-%d %H:%M:%S") print(t) datetime模块 import datet ...

  4. python中时间日期格式化符号

    python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...

  5. Python小代码_2_格式化输出

    Python小代码_2_格式化输出 name = input("name:") age = input("age:") job = input("jo ...

  6. python -- while循环,格式化输出,运算符,初识编码

    一.while循环 1.语法 while   条件: 循环体(结果) 如果条件为真,则直接执行结果),然后再次判断条件,知道条件为假,停止循环. while True: print('你是谁呢') 退 ...

  7. Python的三种格式化输出

    今天刚学了python的三种格式化输出,以前没接触过这么有趣的输出方式,现在来分享一下. #!/user/bin/env python#coding:utf-8#三种格式化输出 #第一种格式化输出na ...

  8. python中json格式数据输出实现方式

    python中json格式数据输出实现方式 主要使用json模块,直接导入import json即可. 小例子如下: #coding=UTF-8 import json info={} info[&q ...

  9. Java中数字的格式化输出

    Java中数字的格式化输出 double d = 345.678; String s = "hello!"; int i = 1234; //"%"表示进行格式 ...

随机推荐

  1. TP 接收post请求使用框架自带函数I()防止注入

    <input id="dele_id[]" value="1" type="checkbox" /> <input id= ...

  2. 进程间通信(IPC)+进程加锁解锁

    [0]README 0.1) source code and text description are from orange's implemention of a os: 0.2) for com ...

  3. Unity3D研究院编辑器之脚本设置ToolBar及脚本设置顶视图

    Unity版本5.3.2 如下图所示,ToolBar就是Unity顶部的那一横条.这里的所有按钮一般情况下都得我们手动的用鼠标去点击.这篇文章我们说说如果自动操作它们 1.自动点击左边四个按钮 (拖动 ...

  4. iOS 使用 Core Plot 绘制统计图表入门

     本文转载至 http://blog.csdn.net/zhibudefeng/article/details/7677457   iOS(iPhone/iPad) 下图形组件有两个有名的,s7gra ...

  5. Makefile注意点总结

    1 "="和":=" "="号赋值时,如果右边的值里面有未展开的变量,要等到整个Makefile的变量处理完之后,再展开,也就是说,如果该未 ...

  6. iOS改变UIAlertView、UIActionSheet、UIAlertController系统字体颜色

    废话不多说,直接上代码,效果是最好的说服力 1.改变UIAlertView字体颜色 [UIView appearance].tintColor = [UIColor greenColor]; 个人还是 ...

  7. 【题解】P3258松鼠的新家

    [题解][P3258 JLOI2014]松鼠的新家 树链剖分板子题. 总结一点容易写错的地方吧: if(d[top[u]]<d[top[v]]) swap(u,v);注意是\(top\). 在\ ...

  8. php标准库DirectoryIterator类的操作说明

    <?php $dir = new DirectoryIterator(dirname(__FILE__)); foreach ($dir as $fileInfo) { if ($fileInf ...

  9. Flask:模板

    模板是一个包含响应文本的文件,其中包含用占位变量表示的动态部分,具体值只在请求的上下文中才能知道.使用真实值替换变量,再返回最终得到的响应字符串.这个过程称为渲染,为了渲染模板,Flask使用了一个名 ...

  10. memcache-session-manager(flexjson)

    MSM项目FlexJson序列化参考文档. 序号(步骤) 需求描述 jar包列表: spymemcached-2.11.1.jar memcached-session-manager-tc8-1.8. ...