I wrote a console application that uses the logging module. I used logging.Formatter("%(module)s:%(lineno)d") to help in debugging the code.
I find everything works fine when calling file.py but when I call file.exe something odd happens to the formatted information.
Instead of providing the module name and the associated line number, it always lists "__init__:988" as the source.
I investigated where this is coming from and found the following:
961 def findCaller(self):
963 Find the stack frame of the caller so that we can note the source
964 file name and line number.
966 f = sys._getframe(1)
967 while 1:
968 co = f.f_code
969 filename = os.path.normcase(co.co_filename)
970 if filename == _srcfile:
971 f = f.f_back
973 return filename, f.f_lineno
982 def _log(self, level, msg, args, exc_info=None):
984 Low-level logging routine which creates a LogRecord and then calls
985 all the handlers of this logger to handle the record.
987 if _srcfile:
988 fn, lno = self.findCaller()
990 fn, lno = "<unknown file>", 0
991 if exc_info:
992 exc_info = sys.exc_info()
993 record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info)
Has anyone's code exhibited similar behaviour and what was done to provide proper formatted information? I understand the *.pyc files are all in a shared zip file and would not provide paths but at least should provide the name of the module and it's associated line number.
This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate or distribute it; do not open any attachments, delete it immediately from your system and notify the sender promptly by e-mail that you have done so. Thank you.