Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81516
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'handler': 0.05; 'output': 0.05; 'root': 0.05; '"""': 0.07; 'sys': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:/ 10': 0.09; 'python': 0.11; 'handler.': 0.16; 'hint': 0.16; 'logger': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:PYTHON': 0.16; 'threshold': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; '(a)': 0.24; 'skip:% 10': 0.24; 'skip:l 30': 0.24; 'question': 0.24; 'logging': 0.26; 'switch': 0.26; 'header:X-Complaints-To:1': 0.27; 'respective': 0.29; 'related': 0.29; 'ignored.': 0.30; 'sets': 0.30; 'url:mailman': 0.30; 'code': 0.31; '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; 'add': 0.35; 'there': 0.35; 'module.': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'error.': 0.37; 'level': 0.37; 'nov': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'url:mail': 0.40; 'even': 0.60; 'read': 0.60; 'simple,': 0.60; 'levels': 0.65; 'between': 0.67; 'sound': 0.68; 'disappear': 0.84; 'subject:skip:S 10': 0.84; 'severe': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: PYTHON LOGGING with StreamHandler and FileHandler |
| Date | Tue, 25 Nov 2014 16:06:35 +0100 |
| Organization | None |
| References | <CACT3xuWoUO=vdoN0hmPU_283W4ihz=+z4WMgMV3kOBFiZEyyww@mail.gmail.com> <87ppcbn5e4.fsf@handshake.de> <CACT3xuVf-Mq2ThPMpCdEvn==E_NwRrFCbNgT-T7ERAzVgLTNDQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd89d3.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| 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.16286.1416928009.18130.python-list@python.org> (permalink) |
| Lines | 81 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1416928009 news.xs4all.nl 2887 [2001:888:2000:d::a6]:32788 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Body-CRC | 1996037738 |
| X-Received-Bytes | 5513 |
| Xref | csiph.com comp.lang.python:81516 |
Show key headers only | View raw
Ganesh Pal wrote:
> 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 .
Quoting
<https://docs.python.org/2.7/library/logging.html#logging.Logger.setLevel>
"""
Logger.setLevel(lvl)
Sets the threshold for this logger to lvl. Logging messages which are less
severe than lvl will be ignored.
"""
INFO is both below WARNING and ERROR. If you add
logger.warn("whatever")
to your code 'whatever' will disappear from your log when you switch the
level from WARNING to ERROR.
> 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
Re: PYTHON LOGGING with StreamHandler and FileHandler Peter Otten <__peter__@web.de> - 2014-11-25 16:06 +0100
csiph-web