logging.config.fileConfig FileHandler configure to write to APP_DATA
I have a logging configuration file that I load via logging.config.fileConfig. The configuration file, configures a FileHandler to log to file. I wish to initialize the FileHandler to the path os.environ['APP_DATA']. However, I don't know how to configure anything other than a static path. I also don't know how to modify the initialization after loading via fileConfig. For example, if I could do something like this then I could make it work for me. logging.config.fileConfig('logging.conf') for logger in enumerate_all_loggers(): logger.addHandler( FileHandler(logfilename, mode='w')) -- http://mail.python.org/mailman/listinfo/python-list
Re: logging.config.fileConfig FileHandler configure to write to APP_DATA
I figured out a method to enumerate all loggers. root = logging.getLogger() for key in root.manager.loggerDict.keys(): logger = logging.getLogger(key) -- http://mail.python.org/mailman/listinfo/python-list
Re: logging.config.fileConfig FileHandler configure to write to APP_DATA
I figured out what I was after. logfn = os.path.join(os.environ['APPDATA'], directory, filename) ensure_path(logfn) logging.config.fileConfig("logging.conf", defaults={'logfn': logfn}) In the config file use: [handler_fileHandler] class=FileHandler level=DEBUG formatter=simpleFormatter args=(r'%(logfn)s', 'w') -- http://mail.python.org/mailman/listinfo/python-list
Re: logging.config.fileConfig FileHandler configure to write to APP_DATA
I was sent via email an alternative solution which is working even better for me. In Python code use: class AppFileHandler(logging.FileHandler): def __init__(self, *args): filename, mode = args if not os.path.isabs(filename): filename = os.path.join(os.environ['APPDATA'], someDirectory, filename) logging.FileHandler.__init__(self, filename, mode) logging.AppFileHandler = AppFileHandler logging.config.fileConfig("logging.conf") In the logging configuration file use: [handler_fileHandler] class=AppFileHandler level=DEBUG formatter=simpleFormatter args=('vector.log', 'w') This solution is better, because I am also using logging.config.listen() which allows a new config file to be sent via a socket to reconfigure a running process's logging. When calling the parser directly I could pass a dictionary with the log filename, but when invoking via the socket, the parser is called indirectly and I could not pass it the dictionary. The AppFileHandler solution works via the socket listener also. -- http://mail.python.org/mailman/listinfo/python-list
cx_Freeze ImportError, how do I debug this
I am building a standalone Windows executable using cx_Freeze. The resulting executable will not run and writes the following error to the console. ImportError: could not import gobject (error was: 'No module named gobject') The project using the gtk libraries for Cairo and Pango on Windows. The program runs fine when run with Python. I have tried copying anything that cx_Freeze may have missed from the gtk installation under the Python directory. My question is, is there a method to debug this, that can tell me more about what is going on? The executable directory already contains _gobject.pyd libgobject-2.0-0.dll libcairo-gobject-2.dll and a bunch of other stuff. I can type import gobject in the Python shell and that works. -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_Freeze ImportError, how do I debug this
On Jan 10, 8:21 pm, Jeffrey Britton wrote: > I am building a standalone Windows executable using cx_Freeze. > The resulting executable will not run and writes the following error > to the console. > > ImportError: could not import gobject (error was: 'No module named > gobject') > > The project using the gtk libraries for Cairo and Pango on Windows. > The program runs fine when run with Python. > I have tried copying anything that cx_Freeze may have missed from the > gtk installation under the Python directory. > > My question is, is there a method to debug this, that can tell me more > about what is going on? > > The executable directory already contains > _gobject.pyd > libgobject-2.0-0.dll > libcairo-gobject-2.dll > and a bunch of other stuff. > > I can type > import gobject > in the Python shell and that works. I just realized that I can import just Cairo and build and executable. However, a test script with simply import Pango print 'hello' fails. This time I tried building with PyInstaller and I get the same error about not being able to load gobject. -- http://mail.python.org/mailman/listinfo/python-list