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


Groups > comp.lang.python > #81510

Re: PYTHON LOGGING with StreamHandler and FileHandler

References <CACT3xuWoUO=vdoN0hmPU_283W4ihz=+z4WMgMV3kOBFiZEyyww@mail.gmail.com> <87ppcbn5e4.fsf@handshake.de>
Date 2014-11-25 19:00 +0530
Subject Re: PYTHON LOGGING with StreamHandler and FileHandler
From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16283.1416922210.18130.python-list@python.org> (permalink)

Show all headers | 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