I was trying to change the logging format by adding a context filter. My Format is like this
FORMAT = "%(asctime)s %(VAL)s %(message)s"
This is the class I use to set the VAL in the format.
class TEST:
def __init__(self, val):
self.test_var=threading.local()
self.test_var.value=val
def filter(self,record):
record.VAL=self.test_var.value
return True
def setValue(self,val)
self.test_var.value=CMDID
It works fine in a single threaded environment, but for a certain multi-threaded environment I get the error
<Fault 1: "exceptions.AttributeError:'thread._local' object has no attribute 'value'">
Can anyone tell me what's wrong here ?? and how to rectify?
Well, the exception is telling you that the
thread._local
object returned fromthreading.local()
doesn't have avalue
attribute that you can assignval
to. You can confirm that by adding adir(self.test_var)
after theself.test_var=threading.local()
line. That returns this for me:Indeed,
help(threading.local())
will show you the methods and attributes that do exist -value
is not among them.If you are attempting to add a new attribute, then perhaps you want:
This will actually create the attribute and assign the value to it.
Instance attributes are not generally created simply by assigning to them, like non-instance variables are...