1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| << Log4pyDictConfig.py >> # encoding:utf-8
import logging,logging.config
print("log4py dictionary configuration")
LOG_DICT= { 'version':1, 'loggers':{ 'root':{ 'level':'DEBUG', 'handlers':['streamHandler','fileHandler','rotateHandler'] }, 'stream':{ 'level':'DEBUG', 'handlers':['streamHandler'] }, 'tempFile':{ 'level':'DEBUG', 'handlers':['fileHandler'] }, 'rotateFile':{ 'level':'INFO', 'handlers':['rotateHandler'] } }, 'handlers':{ 'streamHandler':{ 'class':'logging.StreamHandler', 'level':'DEBUG', 'formatter':'streamFmt', 'stream':'ext://sys.stdout' }, 'fileHandler':{ 'class':'logging.FileHandler', 'level':'DEBUG', 'formatter':'streamFmt', 'filename':'tempFile.log', 'mode':'w' }, 'rotateHandler':{ 'class':'logging.handlers.RotatingFileHandler', 'level':'INFO', 'formatter':'rotateFmt', 'filename':'rotateFile.log', 'mode':'a', 'maxBytes':10485760, 'backupCount':5 } }, 'formatters':{ 'streamFmt':{ 'format':'[ %(levelname)-8s ] %(asctime)s.%(msecs)d %(module)s %(funcName)s %(message)s', 'datefmt':'%H:%M:%S' }, 'rotateFmt':{ 'format':'[ %(levelname)-8s ] %(asctime)s %(module)s %(funcName)s %(message)s' } } }
logging.config.dictConfig(LOG_DICT) log = logging.getLogger("root")
log.debug("Debug Testing ...") log.info("Info Testing ...") log.warn("Warn Testing ...") log.warning("Warinig Testing ...") log.error("Error Testing ...") log.fatal("Fatal Testing ...") log.critical("Critical Testing ...")
logging.shutdown()
|