Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21272
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <dreadpiratejeff@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.019 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'debug': 0.03; 'sys': 0.05; 'created,': 0.09; 'handlers': 0.09; 'to:name:python list': 0.09; 'essentially': 0.10; 'skip:v 30': 0.15; 'logging,': 0.16; 'subject:logging': 0.16; 'subject:Help': 0.17; 'subject:problem': 0.19; 'trying': 0.21; 'file,': 0.21; 'wrong?': 0.23; 'code': 0.26; 'import': 0.27; "i'm": 0.28; 'message-id:@mail.gmail.com': 0.29; "skip:' 10": 0.29; 'skip:% 10': 0.30; 'error': 0.30; 'file.': 0.31; 'skip:l 30': 0.32; 'idea': 0.32; 'file': 0.34; 'skip:# 10': 0.34; 'hi,': 0.34; 'to:addr:python-list': 0.35; 'however,': 0.35; 'things': 0.35; 'received:209.85.160': 0.36; 'run': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'subject:with': 0.37; 'received:209.85': 0.38; 'event': 0.38; 'some': 0.38; 'doing': 0.38; 'couple': 0.38; 'getting': 0.38; 'received:209.85.160.46': 0.39; 'received:mail-pw0-f46.google.com': 0.39; 'option': 0.39; 'logs': 0.39; 'received:209': 0.39; 'setup': 0.40; 'to:addr:python.org': 0.40; 'header:Received:6': 0.61; 'console,': 0.84; 'guts': 0.84; 'not...': 0.84; 'skip:v 60': 0.84 |
| Received-SPF | pass (google.com: domain of dreadpiratejeff@gmail.com designates 10.68.230.134 as permitted sender) client-ip=10.68.230.134; |
| Authentication-Results | mr.google.com; spf=pass (google.com: domain of dreadpiratejeff@gmail.com designates 10.68.230.134 as permitted sender) smtp.mail=dreadpiratejeff@gmail.com; dkim=pass header.i=dreadpiratejeff@gmail.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=VuNfDh2IAk9nBl8OVTj87RErPVvHhZMqX1WpCk8Np3g=; b=cxyPZeDuax4W2r/ErFoETPJh0Uf8sODmEA1+ykussjISnXYlESslMh4Xy5jQ6+EvDc pd3mX3ZhgKXGN3rcCso7HYQ+Q05VTYVo6g9p7ntdn0EztUjiiQdywr3Mtojoa9pJvS4n ThKkLPO1Fzn/BZSy5jKQ6tXYK61kTSCJnbWH+OKn3mbzWzZQRUoGrE8TdFtViWqFoPf8 zKCTjdM5DZu1Iek8VsVpNDbtkuevMQJfnHM1FetKjqsEqK6IRNbqbx0EywHTog81nNh8 RGnozSqok+hniV33+Ujb+YiWVsgI90d+s58MoprsCZ89cM7GmdgTyHZ6t+0xQtaEQ9Ac BbzA== |
| MIME-Version | 1.0 |
| From | J <dreadpiratejeff@gmail.com> |
| Date | Tue, 6 Mar 2012 11:09:23 -0500 |
| Subject | Help me with weird logging problem |
| To | Python List <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| 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.430.1331050187.3037.python-list@python.org> (permalink) |
| Lines | 56 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1331050187 news.xs4all.nl 6840 [2001:888:2000:d::a6]:46460 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21272 |
Show key headers only | View raw
Hi,
I'm trying to add a couple log handlers to a program. The end goal is
to log things at INFO or above to console, and if a -v option is set
to ALSO log everything at DEBUG or above to a file. However, while I
DO get the log file created, and log messages are appearing there,
Debug messages are not...
Here's some sample code that is essentially the guts of the logging
setup right now, based on what I read in the docs:
#!/usr/bin/python
import logging
import sys
verbose = True
# Set up the logger
console_format = '%(levelname)-8s %(message)s'
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter(console_format))
console_handler.setLevel(logging.INFO)
logger = logging.getLogger()
logger.addHandler(console_handler)
if verbose:
verbose_format = '%(asctime)s %(levelname)-8s %(message)s'
verbose_handler = logging.FileHandler('testlog.log')
verbose_handler.setLevel(logging.DEBUG)
verbose_handler.setFormatter(logging.Formatter(verbose_format))
logger.addHandler(verbose_handler)
logging.debug("Setting log level to DEBUG for verbosity")
logging.info("INFO event logged")
logging.warning("WARNING event logged")
logging.error("ERROR event logged")
logging.critical("CRITICAL event logged")
logging.debug("DEBUG event logged")
When I run this I get the following console and log file output:
bladernr@klaatu:~/development/cert-submit-script-improvements/bin$ ./logtest.py
WARNING WARNING event logged
ERROR ERROR event logged
CRITICAL CRITICAL event logged
bladernr@klaatu:~/development/cert-submit-script-improvements/bin$ cat
testlog.log
2012-03-06 11:05:40,297 WARNING WARNING event logged
2012-03-06 11:05:40,297 ERROR ERROR event logged
2012-03-06 11:05:40,298 CRITICAL CRITICAL event logged
So I AM getting logging, but I am not getting the DEBUG level logs in
the log file, nor am I getting INFO level logs on console.
Any idea what I'm doing wrong?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Help me with weird logging problem J <dreadpiratejeff@gmail.com> - 2012-03-06 11:09 -0500
Re: Help me with weird logging problem Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2012-03-06 08:19 -0800
Re: Help me with weird logging problem J <dreadpiratejeff@gmail.com> - 2012-03-06 12:03 -0500
csiph-web