This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Wrong pathname value in logging output
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: simleo, vinay.sajip
Priority: normal Keywords:

Created on 2006-12-15 14:30 by simleo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg30814 - (view) Author: Tekkaman (simleo) Date: 2006-12-15 14:30
When trying to log caller pathname information, instead of the actual caller's name I get the full name of the logging module source file:

>>> import logging
>>> logging.basicConfig(format='%(pathname)s')
>>> logging.getLogger('').critical('foo')
/usr/lib/python2.4/logging/__init__.py
>>>

I've been discussing this on comp.lang.python and the suspect arised that this has something to do with a symlink in the path leading to the module source file (I have a lib -> lib64 symlink on my system). To verify this I copied the entire logging directory into my home dir and retried. This is what I got:

>>> import logging
>>> logging.basicConfig(format='%(pathname)s')
>>> logging.getLogger('').critical('foo')
<stdin>
>>>

Additional info:
Python Version: 2.4.3
OS: Gentoo Linux 2.6.17-r8
CPU: AMD Turion(tm) 64 Mobile Technology
sys.path: ['', '/usr/lib/portage/pym', '/usr/lib/python24.zip', '/usr/lib64/python2.4', '/usr/lib64/python2.4/plat-linux2', '/usr/lib64/python2.4/lib-tk', '/usr/lib64/python2.4/lib-dynload', '/usr/lib64/python2.4/site-packages', '/usr/lib64/python2.4/site-packages/Numeric', '/usr/lib64/python2.4/site-packages/dbus', '/usr/lib64/python2.4/site-packages/gtk-2.0']
msg30815 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-12-15 17:20
Sorry, why is this wrong? You are making the logging call from an interactive prompt - so you would expect to get the pathname of <stdin>, would you not?

I get the same output on Windows where the only logging module is the one which is part of the standard Python installation.

msg30816 - (view) Author: Tekkaman (simleo) Date: 2006-12-16 19:03
I don't get <stdin>, I get "/usr/lib/python2.4/logging/__init__.py". I got <stdin> (correct behaviour) only after copying the entire logging directory in the same place where I started the interpreter.
msg30817 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-12-16 22:38
Right, but I'm not sure the problem's in logging. Logging uses the filename built into the compiled code objects as it walks up the stack, looking for a filename which is not the source file of the logging package. Try deleting all your .pyc and .pyo files (including the ones in the logging package) and see if there is a change in behaviour; what value does logging._srcFile have? Does it accord with what you would expect? The symlink could mean that the compiled filename in the .pyc/.pyo is out of date.
msg30818 - (view) Author: Tekkaman (simleo) Date: 2006-12-18 09:29
Deleting all .pyc and .pyo files solved the problem. Now I get the correct behaviour. However, this is not an option for a machine on which one does not have root privileges. Can the code be changed in such a way that it's not fooled by outdated .pyc and .pyo files?
msg30819 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-12-18 09:54
Glad the problem's solved. It's not appropriate to change the current behaviour of logging with respect to determining the source file of a module, for a couple of reasons:

1) There are other problems caused by out-of-date .pyo and .pyc files (every use of __file__ is potentially a problem) - which changing logging would not solve. Logging uses __file__ how it is intended to be used.
2) Some systems are shipped with .pyo and .pyc files only - no .py files are available (e.g. frozen systems).
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44342
2006-12-15 14:30:41simleocreate