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


Groups > comp.lang.python > #81510

Re: PYTHON LOGGING with StreamHandler and FileHandler

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ganesh1pal@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'handler': 0.05; 'output': 0.05; 'root': 0.05; 'skip:l 60': 0.07; 'sys': 0.07; 'skip:/ 10': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'handler.': 0.16; 'hint': 0.16; 'logger': 0.16; 'skip:l 90': 0.16; 'subject:PYTHON': 0.16; '\xc2\xa0i': 0.16; 'wrote:': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; '(a)': 0.24; 'skip:% 10': 0.24; 'skip:l 30': 0.24; 'question': 0.24; 'cc:2**0': 0.24; '&gt;': 0.26; 'logging': 0.26; 'header:In-Reply- To:1': 0.27; 'respective': 0.29; 'related': 0.29; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; '25,': 0.31; 'skip:= 20': 0.31; 'handled': 0.32; 'url:python': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'info': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'module.': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'level': 0.37; 'nov': 0.38; 'pm,': 0.38; 'skip:p 20': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; 'even': 0.60; 'read': 0.60; 'simple,': 0.60; 'levels': 0.65; 'between': 0.67; 'sound': 0.68; 'url:info': 0.73; 'subject:skip:S 10': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=erG7zwCLcJcsgVuUoNc0ZDyAXg0QJisSGl/01UN4DvQ=; b=HPsXn3yCUnPA1gcFjmaEQqr6S1W2wCwqAXia4QUYVTJgy82iSz1NAqmxVA0ad/h0c9 FP/HaCWjpcBS52kzgzcAQ+AzoTz3ejkJQhkOb/AvRN0yZYef3iWBSI0tQ3s7XwARCKgr A14jHKp4pgCuH5KcJodDm+v/Rso8tu7mfoILXnscV2udInuR4841vMaPmHsbw2xDp72L 4c0SVWtJi7x56Wb+PdFVEUnWu2EHKxdSOP6CgYjPFmE8A7OYZmE3Pd7GWXgCJe0hJrs6 7NfZEyz7QNxsGup9qw8qV4I0wqzRD1syQMOVjjL+qS89w9VCScePS1TC+kJbQIlPlNXf 91Xw==
MIME-Version 1.0
X-Received by 10.152.10.67 with SMTP id g3mr27313607lab.59.1416922202231; Tue, 25 Nov 2014 05:30:02 -0800 (PST)
In-Reply-To <87ppcbn5e4.fsf@handshake.de>
References <CACT3xuWoUO=vdoN0hmPU_283W4ihz=+z4WMgMV3kOBFiZEyyww@mail.gmail.com> <87ppcbn5e4.fsf@handshake.de>
Date Tue, 25 Nov 2014 19:00:02 +0530
Subject Re: PYTHON LOGGING with StreamHandler and FileHandler
From Ganesh Pal <ganesh1pal@gmail.com>
To dieter <dieter@handshake.de>
Content-Type multipart/alternative; boundary=001a1132f4a089dc470508aee8cf
Cc "python-list@python.org" <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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16283.1416922210.18130.python-list@python.org> (permalink)
Lines 115
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416922210 news.xs4all.nl 2859 [2001:888:2000:d::a6]:40152
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81510

Show key headers only | View raw


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

Thanks for the hint ,  I was able to get the error messages on the console
 by setting the StreamHandler level to WARNING .

It works for  me know  but    one  LAST  question , it might sound simple,
but  Iam not able to understand the difference between

- (a)   ch.setLevel(logging.WARNING)  and ch.setLevel(logging.ERROR) , both
are giving the same output for the below program .



import logging
import sys

# StreamHandler

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
%(message)s')

root = logging.getLogger()
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.WARNING)  =========================> (  even with
ch.setLevel(logging.ERROR) I get the same output )
ch.setFormatter(formatter)
root.addHandler(ch)

# FileHandler

ch1  = logging.FileHandler('/var/tmp/myapp1.log')
ch1.setFormatter(formatter)
logger = logging.getLogger('myapp')
logger.setLevel(logging.DEBUG)
logger.addHandler(ch1)
logger.error('We have a problem')
logger.info('While this is just chatty')


# echo > /var/tmp/myapp1.log
# python final_logger.py
2014-11-25 13:16:35,772 - myapp - ERROR - We have a problem
# cat /var/tmp/myapp1.log

2014-11-25 13:16:35,772 - myapp - ERROR - We have a problem
2014-11-25 13:16:35,773 - myapp - INFO - While this is just chatty

Regards,
Ganesh




On Tue, Nov 25, 2014 at 12:17 PM, dieter <dieter@handshake.de> wrote:

>
> You read the handler related documentation of the logging module.
> When I remember right, you will find there a method allowing you
> to control which message levels are handled by the the respective handler.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

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


Thread

Re: PYTHON LOGGING with StreamHandler and FileHandler Ganesh Pal <ganesh1pal@gmail.com> - 2014-11-25 19:00 +0530

csiph-web