Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41115

Re: Missing logging output in Python

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <matt@tplus1.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'output': 0.04; 'root': 0.04; 'subject:Python': 0.05; 'debug': 0.05; 'method.': 0.05; '__name__': 0.07; 'permissions': 0.07; 'skip:/ 10': 0.07; 'python': 0.09; '###': 0.09; 'from:addr:matt': 0.09; 'logger': 0.09; 'script,': 0.09; 'stdout': 0.09; 'sys.stderr': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'skip:f 30': 0.15; "'__main__':": 0.16; 'loggin': 0.16; 'stderr:': 0.16; '\xa0maybe': 0.16; 'wrote:': 0.17; '8bit%:3': 0.17; 'module': 0.19; 'define': 0.20; 'email addr:gmail.com&gt;': 0.20; 'import': 0.21; 'file:': 0.22; 'skip:% 10': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'setting': 0.26; 'am,': 0.27; 'logging': 0.27; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'run': 0.28; 'cat': 0.29; 'url:mailman': 0.29; '8bit%:5': 0.29; 'maybe': 0.29; 'fri,': 0.30; 'writes': 0.30; 'error': 0.30; 'stuff': 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'info': 0.32; 'url:listinfo': 0.32; 'received:74.125.82': 0.33; 'skip:l 40': 0.33; 'hi,': 0.33; 'skip:d 20': 0.34; 'program,': 0.34; 'received:google.com': 0.34; 'whatever': 0.35; 'skip:f 40': 0.35; 'skip:l 30': 0.35; 'add': 0.36; 'but': 0.36; 'received:74.125': 0.36; 'url:org': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'end': 0.40; 'url:mail': 0.40; 'enable': 0.60; 'your': 0.60; 'matthew': 0.65; 'url:info': 0.75; '2013': 0.84; 'use\xa0': 0.84; 'works!': 0.84; 'wilson': 0.91
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=HNcMPscnaOE8k8n14x278FnHug5EDwL8yy6Tt4BQBrs=; b=cLdwwa7m92sPhk3AW23fCUbOD0j5ZpCJeTQnfK7bqbuvBQdwQjO0n2sHp0DUBCoE/X eSbdMrJUmKi6zhrTzlVMdEsKdk2hBubwvcVzkBJZQvItfR7y2U3zDFBDx+H7WBA5WGNz +IV3jVUcbc1/TDfe/pk5supaXJamij7LQ+WKTwO7s1pBn1EC2Ei9bEm7g2TNF1B7haCh jrMXFgqPgrjagnq0SeyWg0mwmz7XQeADuocxLbWdqC36c6DbzDXqWlJa3PcWFUwW2Kaj eQdHnCLiIJ/HHIQfsKaJe/WzAAPOsBuKiIu7e+vG8NTxDYq2kEYVqhzXkZm3AMRGizk6 wIqQ==
MIME-Version 1.0
X-Received by 10.180.97.132 with SMTP id ea4mr18943472wib.23.1363088021060; Tue, 12 Mar 2013 04:33:41 -0700 (PDT)
In-Reply-To <b570d558-706d-4d2d-af81-41c44e2a3a21@googlegroups.com>
References <b570d558-706d-4d2d-af81-41c44e2a3a21@googlegroups.com>
Date Tue, 12 Mar 2013 07:33:40 -0400
Subject Re: Missing logging output in Python
From "W. Matthew Wilson" <matt@tplus1.com>
To gabor.a.halasz@gmail.com
Content-Type multipart/alternative; boundary=f46d04426c4e4b161f04d7b8a9e2
X-Gm-Message-State ALoCoQlIHcCc5OGGA47vUxpT8mRpu2uFIKtkGcEw+wEuZ3VxJsE3jmRBsbK3WDskFXJ8mCK2Zr2P
Cc python-list@python.org
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.3222.1363088028.2939.python-list@python.org> (permalink)
Lines 196
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363088028 news.xs4all.nl 6908 [2001:888:2000:d::a6]:34372
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41115

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

I made that code into a program like this:

### BEGIN

import logging

def configure_logging():

    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s
%(name)-12s %(levelname)8s %(message)s',
                        datefmt='%Y-%m-%d\t%H:%M:%s',
                        filename='/tmp/logfun.log', filemode='a')

    # define a Handler that writes INFO messages to sys.stderr
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)

    # set format that is cleaber for console use
    formatter = logging.Formatter('%(name)-12s: %(levelname)-8s
%(message)s')

    # tell the handler to use this format
    console.setFormatter(formatter)

    # add the handler to the root logger
    logging.getLogger('').addHandler(console)

if __name__ == '__main__':

    configure_logging()

    logging.debug('a')
    logging.info('b')
    logging.warn('c')
    logging.error('d')
    logging.critical('e')

### END

and when I run the program, I get INFO and greater messages to stderr:

$ python logfun.py
root        : INFO     b
root        : WARNING  c
root        : ERROR    d
root        : CRITICAL e

and I get this stuff in the log file:

$ cat /tmp/logfun.log
2013-03-12 07:31:1363087862 root            DEBUG a
2013-03-12 07:31:1363087862 root             INFO b
2013-03-12 07:31:1363087862 root          WARNING c
2013-03-12 07:31:1363087862 root            ERROR d
2013-03-12 07:31:1363087862 root         CRITICAL e

In other words, your code works!  Maybe you should check permissions on the
file you are writing to.

Matt




On Fri, Mar 8, 2013 at 9:07 AM, <gabor.a.halasz@gmail.com> wrote:

> Hi,
>
> I would like to enable loggin in my script using the logging module that
> comes with Python 2.7.3.
>
> I have the following few lines setting up logging in my script, but for
> whatever reason  I don't seem to get any output to stdout  or to a file
> provided to the basicConfig method.
>
> Any ideas?
>
> # cinfiguring logging
> logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s
> %(levelname)8s %(message)s',
>                     datefmt='%Y-%m-%d\t%H:%M:%s',
> filename=config["currentLoop"], filemode='a')
> # define a Handler that writes INFO messages to sys.stderr
> console = logging.StreamHandler()
> console.setLevel(logging.INFO)
> # set format that is cleaber for console use
> formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
> # tell the handler to use this format
> console.setFormatter(formatter)
> # add the handler to the root logger
> logging.getLogger('').addHandler(console)
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
W. Matthew Wilson
matt@tplus1.com
http://tplus1.com

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Missing logging output in Python gabor.a.halasz@gmail.com - 2013-03-08 06:07 -0800
  Re: Missing logging output in Python "W. Matthew Wilson" <matt@tplus1.com> - 2013-03-12 07:33 -0400

csiph-web