[python-win32] com server instantiation mess
Sprinzing, Thomas
Thomas.Sprinzing at bielomatik.de
Mon Nov 22 10:19:55 CET 2004
Hi Folks,
first of all, a short introduction:my name is Thomas Sprinzing, i work for a
company making heavy machinery for paper processing in Germany, and i use
python on win32 for some administrative tasks. I've been using Mark
Hammond's pywim32 for quite a while now, also i am a bit familiar with
zope/plone. I have not been lurking around this list, so i'm a new kid in
this town here.
Anyway, here's my problem (i wrote this to mark, and he proposed to post it
here)
I wrote a com object which basically wraps the python logging module. Then,
from within some strange application, i instantiate two different jscript
threads running in an embedded Windows script host. These are for accessing
the logging com object. So i want to have two distinctive loggers, one
logger "A" logging to A.log, one logger B logging to B.log.
I get them as expected, but: if i log a message to one of the loggers, it
gets written to both logfiles. So there is a problem on python side with the
instantiation. I'll append my pythonscript at the end. Actually, I'm not too
familiar on how to solve this - where should i go and look?
Thanks a lot in advance
Thomas
class loginterface:
_reg_clsid_ = "{1B4F2902-0F6B-4388-96FD-D2F0BE0C0443}"
_reg_desc_ = "Python COM Logging object"
_reg_progid_ = "Bielo.Logger"
_public_methods_ = ['append', 'initialize']
_public_attrs_ = ['formatter_string', 'logfile_size', 'logfile_count' ]
_readonly_attrs_ = []
def __init__(self):
import logging
import logging.handlers
self.logger=logging.getLogger('mylogger')
self.hdlr=''
self.logfile_size = 1048577
self.logfile_count = 10
self.formatter_string = '%(asctime)s %(message)s'
self.loglevel = logging.INFO
def initialize(self, filename):
try:
import os
import winerror
import win32com.server
from win32com.server.exception import COMException
import logging
import logging.handlers
self.abspath=os.path.abspath(str(filename))
self.hdlr=logging.handlers.RotatingFileHandler(self.abspath,'a',self.logfile
_size,self.logfile_count)
self.formatter = logging.Formatter(self.formatter_string)
self.hdlr.setFormatter(self.formatter)
self.logger.addHandler(self.hdlr)
self.logger.setLevel(self.loglevel)
except (TypeError,ValueError):
raise COMException(desc="Fehler beim initialisieren des
Loggers",scode=winerror.ERROR_GENERIC_NOT_MAPPED)
def append(self, meldung):
try:
import logging
import win32com.server
import winerror
from win32com.server.exception import COMException
self.logger.info(meldung.encode('latin-1'))
except (TypeError, ValueError):
raise COMException(desc="Fehler beim loggen: " + ValueError,
scode=winerror.ERROR_GENERIC_NOT_MAPPED)
return 'message logged:' + meldung
if __name__ == '__main__':
import sys
from win32com.server import register
register.UseCommandLine(loginterface)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20041122/7f13876b/attachment.html
More information about the Python-win32
mailing list