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


Groups > comp.lang.python > #17153 > unrolled thread

Re: logging issues

Started byAndrea Crotti <andrea.crotti.0@gmail.com>
First post2011-12-13 17:03 +0000
Last post2011-12-17 12:44 -0800
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: logging issues Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-12-13 17:03 +0000
    Re: logging issues Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2011-12-17 12:44 -0800

#17153 — Re: logging issues

FromAndrea Crotti <andrea.crotti.0@gmail.com>
Date2011-12-13 17:03 +0000
SubjectRe: logging issues
Message-ID<mailman.3606.1323795786.27778.python-list@python.org>
And by the way suppose I have a script which takes as input the log
level and a list of possible filters.
In another file I have a couple of functions as below which are called
in that order.

Is that supposed to work?
In theory I'm getting both times the same logger.
The set_verbosity seems to do its job, the second is also
called and the filters are added but I don't see the output
formatted as it should..
Maybe I can only set it up once?

def set_verbosity(log_level):
     """Set the desired log level
     """
     root_logger = logging.getLogger()
     root_logger.setLevel(LOG_LEVELS[log_level])

def setup_logging(to_filter):
     root_logger = logging.getLogger()
     hdlr = logging.StreamHandler()
     formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
     hdlr.setFormatter(formatter)
     # a list of regular expressions to filter out?
     if to_filter:
         for f in to_filter:
             logger.debug("adding filter for name %s" % f)
             filt = logging.Filter(f)
             hdlr.addFilter(filt)

     root_logger.addHandler(hdlr)

[toc] | [next] | [standalone]


#17418

FromVinay Sajip <vinay_sajip@yahoo.co.uk>
Date2011-12-17 12:44 -0800
Message-ID<1f2ca0bf-4c47-416d-b2d4-e526c56db400@f1g2000yqi.googlegroups.com>
In reply to#17153
On Dec 13, 5:03 pm, Andrea Crotti <andrea.crott...@gmail.com> wrote:

> The set_verbosity seems to do its job, the second is also
> called and the filters are added but I don't see the output
> formatted as it should..

Generally speaking, you should only do logging configuration once, as
Jean-Michel said - from your main() function or "if __name__ ==
'__main__'" suite.

Until you show more detail about what you're getting and what you're
expecting, it's hard to provide more help.

Regards,

Vinay Sajip

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web