Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'output': 0.04; "'',": 0.07; 'scripts': 0.09; 'python': 0.09; 'script,': 0.09; 'stderr': 0.09; 'stdout': 0.09; 'subject:both': 0.09; 'todo:': 0.09; 'def': 0.10; "'()'": 0.16; 'subject:log': 0.16; 'config': 0.17; 'skip:u 30': 0.17; 'subject:] ': 0.19; 'tried': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'instead.': 0.27; 'received:172.30': 0.29; 'writes:': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "skip:' 10": 0.30; 'daniel': 0.30; "skip:' 20": 0.32; 'info': 0.32; 'to:addr:python-list': 0.33; 'received:fr': 0.36; 'should': 0.36; 'subject:[': 0.37; 'level': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'url:12': 0.40; 'success,': 0.62; 'url:blogspot': 0.64; 'limit': 0.65; 'finally': 0.66; 'regards.': 0.66; 'color': 0.69; "'class'": 0.84; 'subject: *': 0.84; 'subject:Making': 0.84; 'subject:skip:l 10': 0.84; 'info,': 0.91; 'url:fr': 0.95 From: Daniel Dehennin To: python-list@python.org Subject: [SOLVED] Re: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? References: <34939e5a-19ba-4cc5-b10b-36f8b2e42830@h9g2000vbr.googlegroups.com> <87objt5u16.fsf@daniel.eole.lan> Organisation: Eole Date: Wed, 24 Oct 2012 11:32:24 +0200 In-Reply-To: <87objt5u16.fsf@daniel.eole.lan> (Daniel Dehennin's message of "Tue, 23 Oct 2012 13:04:21 +0200") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 84 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351071158 news.xs4all.nl 6858 [2001:888:2000:d::a6]:37556 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32025 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Daniel Dehennin 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 =3D level def filter(self, rec): return rec.levelno =3D=3D 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-logg= ing-output # http://plumberjack.blogspot.fr/2010/12/colorizing-logging-output-in-t= erminals.html config =3D { '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= ',=20 'stream' : 'ext://sys.stderr', 'level' : 'WARNING',=20 'formatter' : 'stderr', } }, 'root' : { 'level' : options.log_level.upper(), 'handlers' : ['stdout', 'stderr'], }, } logging.config.dictConfig( config ) return logging.getLogger() #+end_src =2D-=20 Daniel Dehennin EOLE --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iF4EAREKAAYFAlCHta4ACgkQWjgIUPVihwyu7QEA23jMuq6UTjtn2BBwCD4m76Pu /NR3EOHrQkBmIsmG4xwA/jqtgRGdb6MxBotUlQUEqexcBnly67b3aXnV4mkd63V+ =LoAd -----END PGP SIGNATURE----- --=-=-=--