Hi,
I have a C extension which does some logging using the built-in logging
module. The root logger has been configured to include the %(pathname)s:%(lineno)d
fields in the format.
The fields work fine when the logging is done from Python code. However, any log entries from the C extension show /usr/lib64/python3.13/logging/__init__.py:2205
for every logging entry.
The C extension uses the following code to get the root logger:
logging_module = PyImport_ImportModule("vortex.lib.logging");
if (!logging_module)
goto fail;
logging.logger = PyObject_CallMethod(logging_module, "getLogger", NULL);
if (!logging.logger)
goto fail;
return 0;
The call to the logger methods is made with
state = PyGILState_Ensure();
if (!PyObject_CallMethod(logging.logger, log_methods[level], "(s)", msg_str))
PyErr_Print();
PyGILState_Release(state);
The log messages from the C extension are formatted correctly. It’s just that the value for the %(pathname)s:%(lineno)d
fields is showing as a generic value.
Is there a way to make the log messages show correct values for those fields?