Log logging code format

Log logging

Format code

logging Import
looger = logging.getLogger () # create a basket case

Create a file handle, used to record log (file stream)

fh = logging.FileHandler('test1.log',mode="a",encodeing="utf-8")

Create a screen flow, record the contents of print

ch = logging.StreamHandler()

Define a logging format

f_str = logging.Formatter("%(asctime)s %(name)s %(levelname) %(filenname)s %(lineno)s %(message)s")

Set a record level

looger.level = 10

fh.setFormatter (f_str) # handle to the file format of the recorded contents provided
fh.setFormatter (f_str) # console to format the content provided
looger objects looger.addHandler (fh) # add the file handle in
looger.addHandler (ch ) # looger objects will be added in the center console

looger.debug (1234) # We secondary development
looger.info (1234) # We secondary development
looger.warning (1231342)
looger.error (13231)
looger.critical (123)

Common command code
% (name) s Logger names
% (levelno) s digital form log level
% (levelname) s in text form log level
% (pathname) s call to the full path name of the module log output function, may not have
% (filename) s calling module log output function of the name of the file
% (module) s calling module name of the log output function
% (funcName) s call to the function name log output function
% (lineno) d call statement log output function located line
% (created) f the current time, represented by a standard floating point representation UNIX time
, the number of milliseconds since Logger d created when the output log information% (relativeCreated)
% (the asctime) string S of the current time. 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

logging.debug () # own people

Guess you like

Origin www.cnblogs.com/g15009428458/p/11604588.html