Formatted output log in Python

 

Copy the code
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:The PM 56 is 
                    filename=logfile#,  
                    # the fileMode = 'a' will default to a # 
                   ) 

logging.info () #logging added automatically after each line log "\ 000" wrap, the wrap is not Windows 'Valid passed username \ R & lt.' 

#logging output: 
2016-05-26 15:22:29 INFO liu1! Valid # passed. 
# 2016-05-26 15:22:37 INFO liu1! Valid passed.
Copy the code

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

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

Log Level Level: CRITICAL> ERROR> WARNING> INFO> DEBUG> NOTSET

the format parameter string format may be used:
% (name) is the name of S Logger
% (levelno) s digital form log level
% (levelname) s log level text form
% (pathname) s call log output function module the full path name, it may not
% (filename) s calling module log output function filename
% (module) s calling module name log output function
% (funcName) s calling a function for a log output function of
% (lineno) d line of code calls log output function of the statement where
% (created) f the current time, represented by the floating-point standard UNIX time representation
% at (relativeCreated) d output log information, the number of milliseconds since Logger created
% (asctime) s current time string. The default format is "2003-07-0816: 49: 45,896." Milliseconds after the comma
% (thread) d thread ID. It may not have
% (threadName) s thread name. May not be
d Process ID% (process). May not
% (message) s user output message

 

 

Reference link: https: //www.cnblogs.com/dreamer-fish/p/5460929.html

Guess you like

Origin www.cnblogs.com/xiohao/p/11027457.html