Discussion:
[Twisted-Python] Can’t change namespace for the Logger instance
Роман Мещеряков
2017-01-20 09:33:36 UTC
Permalink
_______________________________________________
Twisted-Python mailing list
Twisted-***@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Glyph Lefkowitz
2017-01-21 05:53:18 UTC
Permalink
I expect the text between ‘[‘ and ‘#’ to be ‘ad_hoc’, but it is auto-generated name instead. Am I doing something wrong or this is a bug?
This is indeed a bug! And a pretty serious one; it's explicitly documented to work otherwise. Please file it.

The reason that this happens is that the 'namespace' field is filled out by the descriptor (__get__ method) of the `Logger` object when it is bound to `self`.

You can work around this in the meanwhile by changing your example to be like so:


import sys
from twisted.logger import (Logger, textFileLogObserver)

observer = textFileLogObserver(sys.stdout)

class MyClass:
@property
def log(self):
return Logger(namespace="ad_hoc", observer=observer, source=self)

def __init__(self):
self.log.info("MyClass.__init__ called!")

def __del__(self):
self.log.info("Bye!")

obj = MyClass()

-glyph
Роман Мещеряков
2017-01-23 08:26:46 UTC
Permalink
_______________________________________________
Twisted-Python mailing list
Twisted-***@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Loading...