limitations of current logging package
Vinay Sajip
vinay_sajip at yahoo.co.uk
Sat Oct 2 11:54:00 EDT 2004
More information about the Python-list mailing list
Sat Oct 2 11:54:00 EDT 2004
- Previous message (by thread): help: pypgsql: this code works in Fedora core 1, Not in FC2
- Next message (by thread): limitations of current logging package
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> The above shows clearly that one can use logging in a simple > way, but as Michael points out, it's not well documented how > simple it can be. Even having read this thread and knowing > in advance that I could do that, I wasn't able to find the > relevant information easily in the documentation with > several minutes of reading (and several minutes covers a > lot of territory normally). Even when I found the comments > about the shortcut functions, I wouldn't have been certain > how to use them (as above) because an example is missing. The following documentation, which is in CVS for Python and will be part of the next release, does give information for simple usage: http://www.python.org/dev/doc/devel/lib/minimal-example.html > 2) I wanted my log files written to the application's own > directory, rather than to the current directory. Using > the fileConfig capability, you can't, at least not without > using absolute paths (near as I can tell). > > My hack workaround was to prepopulate the logging module's > vars() with one call _app_path, and then to reference that > in the config file in the following way. This works only > because (a) eval is used on the args, and (b) the os module > has already been imported by logging.__init__: > > (in the main code:) > logging._app_path = MY_APP_PATH > logging.config.fileConfig(MY_CONFIG_FILE) > > (in the config file:) > [handler_hand01] > class=handlers.RotatingFileHandler > level=NOTSET > formatter=form01 > args=(os.path.join(_app_path, 'bod.log'), 'a', 10000000, 9) > > > Now I can sort of see why the second issue might be awkward > to resolve (since it is in effect a problem that appears in > various other ways in the Python world, with no standard > solution, mainly because there's no simple "sys.getappdir()" > or whatever it would be called). You can simply say something like logging.mymodule = mymodule and in the config file, the args for the file handler can, instead of specifying the file name, reference a function such as mymodule.getpathname('myapp.log'), where getpathname prepends the appropriate path. In the same way, you can reference handlers defined in your own module in the config file. > For the first problem, I think the exc_info "flag" should be > changed so that if it contains actual exception info, or > maybe just a tuple of three items, then *that* information > is logged instead of a call to sys.exc_info() being made. Not quite true, although the documentation could be a little clearer. Originally, the exc_info flag was checked for true/false, and this check still holds for deciding whether exception info is logged. However, in recent versions, if an exception tuple (in the same format as returned by sys.exc_info()) is passed, sys.exc_info() is not called and the passed tuple is used instead. I aim to update the documentation to reflect this. Regards, Vinay Sajip
- Previous message (by thread): help: pypgsql: this code works in Fedora core 1, Not in FC2
- Next message (by thread): limitations of current logging package
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list