I created a custom log level as below:
class MyLoggerAdapter(logging.LoggerAdapter):
def __init__(self, logger, extra):
logging.LoggerAdapter.__init__(self, logger, extra)
self.logger = logger
logging.addLevelName(25, "NOTICE")
def notice(self, msg, *args, **kwargs):
self.logger.log(25, msg, *args, **kwargs)
The issue I have is that my logger format uses %(pathname)s
and %(lineno)d
, and whenever I call logger.notice()
those values refer to the line within the definition of the notice method, rather than the location that the method was called from. How do I add the notice
log level but print the correct location of the message to the logs?