On Jan 20, 2017, at 1:33 AM, Роман Мещеряков firstname.lastname@example.org wrote:
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()