Logging module stopped working

Chris Angelico rosuav at gmail.com
Tue Oct 17 00:30:16 EDT 2017


On Tue, Oct 17, 2017 at 3:06 PM, llanitedave
<llanitedave at birdandflower.com> wrote:
> I'm building an application that contains some long-running operations in a separate thread from the user interface.  I've been using the logging module writing logging.info() statements to a .log file to keep track of the data interactions while it runs.
>
> In the midst of a recent run, the logging simply stopped working.  The rest of the application continued on as if nothing had happened, but without the log I'm pretty much blind.
>
> I set up the logging code at the very beginning of the app, before any other work is done.  Here's the relevant code:
>
> #!/usr/bin/env python3
>
> import sys
> import os
> #import functions_classes
> from PyQt5 import QtGui, QtCore, QtWidgets
> from PyQt5.QtGui import *
> from PyQt5.QtCore import *
> from PyQt5.QtWidgets import *
> import sqlite3
> import logging
> import inspect
> import threading
> import datetime
>
> #import local modules
> import qt_EnvTabs
> import globalnames
> import evocontrol
> import inputoutput
>
> class MainWindow(QMainWindow):
>     def __init__(self):
>         super().__init__()
>         # set up logging
>         logging.basicConfig(format='%(levelname)s:%(message)s', filename="sample.log", level=logging.DEBUG)
>         logging.info("Starting system, MainWindow.__init__,  %s", str(datetime.datetime.today()))
>         self.createUI()
>
> I also have an earlier draft of the application that I saved into another directory.  Its initial code is identical to what I posted here.  I opened it, saw the first window activate, and then closed it.  I checked for the sample.log file, it existed, and contained the proper message:
> "INFO:Starting system, MainWindow.__init__,  2017-10-16 20:58:40.988035"
>
> I did the same to the current file, and no log file was created at all!
>
> Between the time that the logging was working and the time it quit, the only
>  changes I made were to add a couple of logging.info() statements into a downstream module.  But that seems irrelevant here, as those modules aren't included in the above test.
>
> Is there any behind-the-scenes behavior that I'm missing?  I'm stumped.

I'd be suspecting that something reconfigured the logging module, most
likely changing the logging level. Audit the modules by either
removing some and seeing if it still happens, or by combing through
the code. Perhaps something was supposed to construct its own logger,
but actually reconfigured the entire module?

ChrisA



More information about the Python-list mailing list