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.

Author alengarbage
Recipients
Date 2005-09-01.04:49:27
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
After upgrading from python 2.2, I noticed that the
logging facility doesn't seem to work in my code anymore.

As far as I can tell, after spending a bit of time
isolating the problem, this is an issue with threading.
 In the main thread, logging works without a hitch.  In
the secondary thread (which is run via
twisted.reactor), any attempt to write to the log
results in:

Traceback (most recent call last):
  File "/usr/lib/python2.4/logging/__init__.py", line
712, in emit
    self.stream.write(fs % msg)
ValueError: I/O operation on closed file

The code that initializes the logger is as follows:
        logger = logging.getLogger('mylogger')
        screenhandler = logging.StreamHandler()
        screenhandler.setLevel(logging.INFO)
        logger.addHandler(self.screenhandler)

        logfile = "/tmp/testlog"
        if os.path.isfile(logfile):
            os.remove(logfile)
        handler = logging.FileHandler(logfile)
        formatter = logging.Formatter('%(asctime)s
%(levelname)s: %(message)s')
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        logger.setLevel(logging.INFO)

Alone, this works fine.  It is only when a the second
thread does a 'logger = logging.getLogger('mylogger')
and subsequently calls 'logger.log()' that the above
error is produced.
History
Date User Action Args
2007-08-23 14:34:09adminlinkissue1277903 messages
2007-08-23 14:34:09admincreate