Reputation: 367
Can I use ContextFilters in python logging to change loglevels based on modulenames. So something like
class ContextFilter(logging.Filter):
CMDID_cf="IAMTEST1"
def __init__(self, CMDID1):
self.CMDID_cf=CMDID1
def filter(self,record):
record.CMDID=self.CMDID_cf
return True
def moduleFilter(self):
//something like below//
if(modulename=="something")
setLevel(logging.ERROR)
#MAIN
**define logger**
obj=ContextFilter()
logging.addFilter(obj.modukeFilter)
In the python documentation I haven't really found out anything about this so any help pointing to this would be great.
Upvotes: 2
Views: 3906
Reputation: 99297
The appropriate way, which is documented here, is to use module-level loggers named with __name__
and to then set their levels as desired in the logging configuration. There's no need to use a Filter
for this.
Upvotes: 2