Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31925
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <daniel.dehennin@ac-dijon.fr> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.024 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'warnings': 0.03; 'output': 0.04; "'',": 0.07; 'scripts': 0.09; 'python': 0.09; 'handlers': 0.09; 'stderr': 0.09; 'stdout': 0.09; 'subject:both': 0.09; 'todo:': 0.09; 'def': 0.10; '2.7': 0.13; 'passing': 0.15; 'above)': 0.16; 'subject:log': 0.16; 'useless.': 0.16; 'config': 0.17; 'skip:` 20': 0.17; '2.x': 0.22; '3.2': 0.22; 'changes,': 0.23; 'feature': 0.24; 'tried': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'instead.': 0.27; 'rest': 0.28; 'received:172.30': 0.29; "skip:' 10": 0.30; 'daniel': 0.30; '(and': 0.32; 'url:python': 0.32; "skip:' 20": 0.32; 'could': 0.32; 'info': 0.32; 'to:addr:python-list': 0.33; 'list': 0.35; 'something': 0.35; 'url:org': 0.36; 'received:fr': 0.36; 'url:library': 0.36; 'should': 0.36; 'level': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'skip:o 20': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'skip:u 10': 0.60; 'success,': 0.62; 'more': 0.63; 'url:blogspot': 0.64; 'here': 0.65; 'limit': 0.65; 'regards.': 0.66; 'believe': 0.69; 'color': 0.69; 'benefit': 0.70; 'url:2011': 0.72; "'class'": 0.84; 'believe,': 0.84; 'sense"': 0.84; 'subject: *': 0.84; 'subject:Making': 0.84; 'subject:skip:l 10': 0.84; 'url:config': 0.84; 'info,': 0.91; 'from.': 0.93 |
| From | Daniel Dehennin <daniel.dehennin@ac-dijon.fr> |
| To | python-list@python.org |
| Subject | Re: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? |
| References | <34939e5a-19ba-4cc5-b10b-36f8b2e42830@h9g2000vbr.googlegroups.com> |
| Organisation | Eole |
| Date | 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2659.1350990282.27098.python-list@python.org> (permalink) |
| Lines | 82 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1350990282 news.xs4all.nl 6910 [2001:888:2000:d::a6]:41820 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:31925 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hello,
>> Unfortunately this setup makes `logging.basicConfig` pretty useless.
>> However, I believe that this is something that more people could
>> benefit from. I also believe, that it just "makes sense" to send
>> warnings (and above) to `stderr`, the rest to `stdout`.
[...]
> Python 2.x is closed to feature changes, and Python 2.7 and Python 3.2
> already support flexible configuration using dictConfig() - see
>
> http://docs.python.org/library/logging.config.html#logging.config.dictConfig
>
> Also, Python 3.3 will support passing a list of handlers to
> basicConfig(): see
>
> http://plumberjack.blogspot.com/2011/04/added-functionality-for-basicconfig=
> -in.html
>
> which will allow you to do what you want quite easily.
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?
Here is my configuration:
#+begin_src python
def init_logging(options):
# TODO: color stderr messages by level if sys.stderr.isatty()
config = { 'version' : 1,
'formatters' : { 'stdout' : { 'format' : '%(message)s',
'datefmt' : '', },
'stderr' : { 'format' : '%(message)s',
'datefmt' : '', },
},
'handlers' : { 'stdout' : { 'class' : 'logging.StreamHandler',
'stream' : 'ext://sys.stdout',
'level' : 'INFO',
'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
Regards.
--
Daniel Dehennin
EOLE
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`? Daniel Dehennin <daniel.dehennin@ac-dijon.fr> - 2012-10-23 13:04 +0200
csiph-web