zoukankan      html  css  js  c++  java
  • Python中日志的格式化输出

    复制代码
    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.
    ') #logging会自动在每行log后面添加"00"换行,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

  • 相关阅读:
    poj 2029 Get Many Persimmon Trees 夜
    poj 1191 棋盘分割 夜
    DOM (四)
    div拖拽, onmousedown ,onmousemove, onmouseup
    闭包理解
    DOM(一)
    内存溢出与内存泄漏
    div随鼠标移动而移动(滚动条)
    对象继承模式
    DOM(二)
  • 原文地址:https://www.cnblogs.com/xiohao/p/11027457.html
Copyright © 2011-2022 走看看