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: 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; '>': 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: <87ppcbn5e4.fsf@handshake.de> Date: Tue, 25 Nov 2014 19:00:02 +0530 Subject: Re: PYTHON LOGGING with StreamHandler and FileHandler From: Ganesh Pal To: dieter Content-Type: multipart/alternative; boundary=001a1132f4a089dc470508aee8cf 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --001a1132f4a089dc470508aee8cf Content-Type: text/plain; charset=UTF-8 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 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 > --001a1132f4a089dc470508aee8cf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks for the hint , =C2=A0I was able to get th= e error messages on the console =C2=A0by setting the StreamHandler level to= WARNING .

It works for =C2=A0me know =C2=A0= but =C2=A0 =C2=A0one =C2=A0LAST =C2=A0question , it might sound simple, but= =C2=A0Iam not able to understand the difference between=C2=A0
- (a) =C2=A0 ch.setLevel(logging.WARNING) =C2=A0and ch.setLeve= l(logging.ERROR) , both are giving the same output for the below program .<= br>

=C2=A0

import lo= gging
import sys

# StreamHandler

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

root =3D lo= gging.getLogger()
ch =3D logging.StreamHandler(sys.stdout)
<= div>ch.setLevel(logging.WARNING) =C2=A0=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D> ( =C2=A0even with ch.setLevel(l= ogging.ERROR) I get the same output )
ch.setFormatter(formatter)<= /div>
root.addHandler(ch)

# FileHandler

ch1 =C2=A0=3D logging.FileHandler('/var/tmp/myap= p1.log')
ch1.setFormatter(formatter)
logger =3D log= ging.getLogger('myapp')
logger.setLevel(logging.DEBUG)
logger.addHandler(ch1)
logger.error('We have a proble= m')
logger.info('While= this is just chatty')


# echo &= gt; /var/tmp/myapp1.log
# python final_logger.py
2014-1= 1-25 13:16:35,772 - myapp - ERROR - We have a problem
# cat /var/= tmp/myapp1.log

2014-11-25 13:16:35,772 - myapp - E= RROR - 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.<= br>
--
https://mail.python.org/mailman/listinfo/python-list

--001a1132f4a089dc470508aee8cf--