I'm building a GUI program that has several a GUI (main) module and 4 different QThread modules. I want to be able to properly log unhandled exceptions and other various information that I specify. So I decided to use the python's built-in logging module.
This is what I configured it as:
logging.basicConfig(filename="ubc.log",
format='%(asctime)-6s: %(name)s - %(levelname)s - %(module)s - %(funcName)s - %(lineno)d - %(message)s',
level=logging.DEBUG)
Per this config, I wanted the logging module to tell me exactly what line an error/information occurred on, in which module, what function did it take place in, etc. However, this is what I get in the log (when I do logging.info("text")):
2011-12-22 16:06:02,072: root - INFO - logging - info - 1592 - Calling load blog names function, tabWidget index is 0
Needless to say, most of this information is of no use to me. Line number is definitely not 1592, function name is not info, and module is not logging.
To reiterate, what I want is this: when I say logging.info("log this"), I want this to appear in the log:
2011-12-22 16:06:02,072: root - INFO - WorkerThread1.py - upload_function(self, email, param) - line number 131 - log this
Is something like this possible, and if so, how?
EDIT: Per request, I'm adding more code:
class UI(QMainWindow, ui_ui.Ui_MainWindow):
def __init__(self, parent=None):
super(BlogCreator, self).__init__(parent)
self.setupUi(self)
self.tabWidget.setCurrentIndex(0)
logging.info("Prda!")
The logging.info("Prda!") is on line 414 of the GUI.py file. As you can see, this message should be written every time the software starts (this is the setupUi). And it is written, but here is what is being written:
2011-12-22 16:53:04,209: root - INFO - logging - info - 1592 - Prda!
EDIT #2 Upon further examination, it seems that it is PyInstaller that somehow screws things up. Running the software directly through the interpreter produces desired results; after the program has been compiled into EXE file, the aforementioned occurs.
logging/__init__.py:1197 findCaller(). Have you tried stepping thru this function in pdb and see where it goes wrong? What version of python are you using?