fine grain logging cotrol

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Mar 23 18:51:42 EDT 2007


En Fri, 23 Mar 2007 19:34:31 -0300, Eric S. Johansson <esj at harvee.org>  
escribió:

> class LoggedType(type):
>      def __new__(mcl, name, bases, classdict):
>          def get_logger(self):
>              tag = "%s.%s" % (name,sys._getframe(1).f_code.co_name)
>              lgr = logging.getLogger(tag)
>              lgr.addFilter(filter_test)
>              return lgr
>
>          classdict["_%s__logger" % name] = property(get_logger)
>          return type.__new__(mcl, name, bases, classdict)
>
> It's probably real obvious but I keep getting a:
>
>    File "C:\Python24\lib\logging\__init__.py", line 539, in filter
>      if not f.filter(record):
> TypeError: unbound method filter() must be called with filter_test
> instance as first argument (got LogRecord instance instead)

I don't get all the details of what's all that stuff for, but from the  
error and traceback, I think you forgot to create the filter_test  
instance. That is, change lgr.addFilter(filter_test) to  
lgr.addFilter(filter_test())

-- 
Gabriel Genellina




More information about the Python-list mailing list