Python Logging Start-up (verbose) to memory, then dumping subsets of that based on configuration settings: Any example? -



Python Logging Start-up (verbose) to memory, then dumping subsets of that based on configuration settings: Any example? -

i'm writing programme complicated configuration settings (with options environment, command line, , couple of possible configuration files). i'd enable verbose "debug" level logging memory during configuration reading , initialization --- , i'd selectively dump some, perchance all, of final logging destinations based on of configuration settings, command line switches , environment values.

does here know of open source illustration @ someone's done sort of thing?

it looks logging: memoryhandler should able ... target=none , calling .settarget() method after configuration parsed. question is, can set memoryhandler loglevel debug, set target different (usually less verbose) loglevel, , .flush() memoryhandler other handler (effectively throwing away of overly verbose entries in process)?

that won't quite work, because memoryhandler's flush() method doesn't check levels before sending them target - buffered records sent. however, utilize filter on target handler, in example:

import logging, logging.handlers class warningfilter(logging.filter): def filter(self, record): homecoming record.levelno >= logging.warning logger = logging.getlogger('foo') mh = logging.handlers.memoryhandler(1000) logger.setlevel(logging.debug) logger.addhandler(mh) logger.debug('bar') logger.warning('baz') sh = logging.streamhandler() sh.setlevel(logging.warning) sh.addfilter(warningfilter()) mh.settarget(sh) mh.flush()

when run, should see baz printed.

python logging configuration

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -