[SOLVED] Re: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`?
Daniel Dehennin
daniel.dehennin at ac-dijon.fr
Wed Oct 24 05:32:24 EDT 2012
More information about the Python-list mailing list
Wed Oct 24 05:32:24 EDT 2012
- Previous message (by thread): Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`?
- Next message (by thread): dirty tara lynn takes on multiple cocks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Daniel Dehennin <Daniel.Dehennin at ac-dijon.fr> writes: > Hello, Hi [...] > I tried to setup the same for my scripts with > "logging.config.dictConfig()" without much success, I want to limit > output to stdout to INFO, everything bellow INFO should be sent to > stderr instead. > > Any hints? I finally find a solution for my script, I added a filter. Regards. #+begin_src python class UniqLevelFilter(logging.Filter): def __init__(self, level): self._level = level def filter(self, rec): return rec.levelno == self._level def init_logging(options): # TODO: color stderr messages by level if sys.stderr.isatty() # http://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output # http://plumberjack.blogspot.fr/2010/12/colorizing-logging-output-in-terminals.html config = { 'version' : 1, 'filters' : { 'stdout' : { '()' : '__main__.UniqLevelFilter', 'level' : logging.INFO, }, }, 'formatters' : { 'stdout' : { 'format' : '%(message)s', 'datefmt' : '', }, 'stderr' : { 'format' : '%(message)s', 'datefmt' : '', }, }, 'handlers' : { 'stdout' : { 'class' : 'logging.StreamHandler', 'stream' : 'ext://sys.stdout', 'level' : 'INFO', 'filters' : ['stdout'], 'formatter' : 'stdout', }, 'stderr' : { 'class' : 'logging.StreamHandler', 'stream' : 'ext://sys.stderr', 'level' : 'WARNING', 'formatter' : 'stderr', } }, 'root' : { 'level' : options.log_level.upper(), 'handlers' : ['stdout', 'stderr'], }, } logging.config.dictConfig( config ) return logging.getLogger() #+end_src -- Daniel Dehennin EOLE -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 229 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-list/attachments/20121024/decaeb41/attachment.sig>
- Previous message (by thread): Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`?
- Next message (by thread): dirty tara lynn takes on multiple cocks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list