the python line 024 (logging module, re module)

1 import logging

  As the name implies, the logging module is used to record the log.

Configuration log file # 
# define three log output format
standard_format = '[% (asctime) s] [% (threadName) s:% (thread) d] [task_id:% (name) s] [% (filename) s: % (lineno) D] '\
' [% (levelname) S] [% (Message) S] '
simple_format =' [% (levelname) S] [% (the asctime) S] [% (filename) S:% ( lineno) D]% (Message) S '
id_simple_format =' [% (levelname) S] [% (the asctime) S]% (Message) S '

directory path # log file
BASE_PATH = os.path.dirname (os.path .dirname (__ file__))
logfile_dir = os.path.join (BASE_PATH, 'log')
# log file name
logfile_name = 'atm.log'
# if defined log directory does not exist create one
if not os.path.isdir ( logfile_dir):
os.mkdir (logfile_dir)
full path to the # log file
logfile_path = os.path.join (logfile_dir,The logfile_name)

# configuration log dictionary
LOGGING_DIC = {
'Version':. 1,
'disable_existing_loggers': False,
'formatters': {
'Standard': {
'the format': standard_format
},
'Simple': {
'the format': simple_format
},
},
'Filters': {},
'handlers': {
# print log to the terminal
'Console': {
'Level': 'the DEBUG',
'class': 'logging.StreamHandler', printed to the screen #
'Formatter': 'Simple'
},
# print to log file
'default': {
'Level': 'DEBUG ',
' class': 'logging.handlers.RotatingFileHandler', saved to a file #
'Formatter': 'Standard',
'filename': logfile_path, # log file
'maxBytes': 1024 * 1024 * 5, # log size 5M
'BACKUPCOUNT':. 5,
'encoding': 'UTF-. 8', # log file coding, longer have to worry about distortion Chinese log
},
},
'Loggers': {
# logging.getLogger (__ name__) get logger configuration
'': {
'handlers': [ 'default', 'Console'], # here the handler are defined above plus two, i.e., both the data written to log file to the screen printing and
'level': 'the DEBUG',
'Propagate': True, # up (the higher level Logger) transmission
},
}
}

   Use as follows:

  1) into the configuration module logs

  import logging.config

  2) Load Log dictionary format

  logging.config.dictConfig(LOGGING_DICT)

  3) using the method and info methods getLogger

  logging.getLogger(name).info(message)

2 import re

  Regular use of some symbol combinations that have special meaning or the method described character string together (referred to as regular expressions).

 

Guess you like

Origin www.cnblogs.com/mmmmmrz/p/12617355.html