Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Using the StyleAdapter from the Cookbookhttps://docs.python.org/3/howto/logging-cookbook.html
With the %(funcName)s formatter
Yields the wrong funcName in 3.11 and later.
No matter where you use the StyleAdapter logger, it always prints "log"
#!/usr/bin/env python3importlogging.handlersimportsysclassMessage:def__init__(self,fmt,args):self.fmt=fmtself.args=argsdef__str__(self):returnself.fmt.format(*self.args)classStyleAdapter(logging.LoggerAdapter):def__init__(self,logger,extra=None):super().__init__(logger,extraor {})deflog(self,level,msg,/,*args,**kwargs):ifself.isEnabledFor(level):msg,kwargs=self.process(msg,kwargs)self.logger._log(level,Message(msg,args), (),**kwargs)logger=StyleAdapter(logging.getLogger(__name__))defmain():root_logger=logging.getLogger()root_logger.setLevel(logging.DEBUG)# create formatterformatter=logging.Formatter('%(asctime)s %(name)s %(funcName)s %(levelname)s %(message)s')# create console handler and set level to debugconsole_handler=logging.StreamHandler()console_handler.setFormatter(formatter)root_logger.addHandler(console_handler)root_logger.info('Logger initialized.')logger.info('test')if__name__=='__main__':sys.exit(main())
PS > py -3.10 test_log.py2024-02-09 23:15:33,506 root main INFO Logger initialized.2024-02-09 23:15:33,506 __main__ main INFO testPS > py -3.12 test_log.py 2024-02-09 23:15:29,298 root main INFO Logger initialized.2024-02-09 23:15:29,299 __main__ log INFO testCPython versions tested on:
3.10, 3.12
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done