Logging module:
By default, logging prints the log to the screen with a log level of warning;
Log level size relationships are: CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET, and of course you can define the log level yourself.
To configure the output format of the logging to the log:
Import logging
Logging.basicconfig (level=logging. DEBUG,
format= '% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s ',
Datefmt= '%a,%d%b%Y%h:%m:%s ',
Filename= ' Myapp.log ',
Filemode= ' W ')
Logging.debug (' This is Debug message ')
Logging.info (' This is Info message ')
Logging.warning (' This is warning message ')
Execute the log to file content as follows:
Fri, 23:38:04 11-10.py[line:16] Debug this is debug message
Fri, 23:38:04 11-10.py[line:17] Info this is info message
Fri, 23:38:04 11-10.py[line:18] WARNING This is WARNING message
"""
Parameters of the Logging.basicconfig function:
FileName: Specify the log file name
FileMode: Same as file function, specify open mode of log file, ' W ' or ' a '
Format: Specifies the formats and contents of the output, format can output a lot of useful information, as in the example above:
% (Levelno) S: Print the value of the log level
% (levelname) S: Print log level name
% (pathname) s: Prints the path of the currently executing program, which is actually sys.argv[0]
% (filename) s: Prints the current name of the executing program
% (funcName) s: Print the current function of the log
% (Lineno) d: Print the current line number of the log
% (asctime) s: Time to print logs
% (thread) d: Print thread ID
% (threadname) s: Print thread name
% (process) d: Print process ID
% (message) s: Print log information
DATEFMT: Specify time format, same as Time.strftime ()
Level: Sets the log levels by default to logging. WARNING
Stream: Specifies the output stream that will log, can specify output to Sys.stderr,sys.stdout or file, default output to Sys.stderr, stream is ignored when stream and filename are specified simultaneously
"""
OS module:
A few common methods:
Os.path.isfile ()
Os.paht.isdir ()
Os.path.exists ()
Os.path.join ()
Os.path.basename ()
Os.system ("Ls-l *.sh") ...
Os.popen (' ls-l * '). ReadLines () ...
SYS module:
A few common methods:
Sys.argv[0]..
Sys.path ()
Some of the modules built into Python