cross-platform logging.config: how to set cross platform log (handlers) file location?

2016-08-09 Thread berteh
Hello.

My python script should run on Linux, Win and MacOS, but I can't find a way to 
have logging.conf configuration that works out of the box accross all these 
OSes.

I don't want my users to have to edit configuration files manually.


If I use a "linux-like" handler configuration such as below it fails on Windows 
when the script is run from a directory from which the user has no write access 
(ie any subfolder or C:\Program Files, that is the default install location)

[handler_file]
class=handlers.RotatingFileHandler
args=('scribusGenerator.log','a','maxBytes=1000','backupCount=1')

And if I use a "windows-like" file location it fails (of course) in Linux and 
MacOSX

[handler_file]
class=handlers.RotatingFileHandler
args=('D:\scribusGenerator.log','a','maxBytes=1000','backupCount=1')


One option would be to set the location dynamically in the system temp 
directory (from tempfile.gettempdir())... but I can't find a way to change the 
location of the handler loaded via config module.

Any piece of advice on how to achieve cross-platform logging that does not 
require a modification by the user?

Thanks.
B.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cross-platform logging.config: how to set cross platform log (handlers) file location?

2016-08-10 Thread Berteh BE
Thanks Peter for the insights that args are passed to eval().
Thanks Steven for the suggestion that ยด~/' may actually work in windows.

Combining both I'm now successfully using the following in my logging.conf 
configuration file, that works in both *nix and Windows:

[handler_file]
class=handlers.RotatingFileHandler
args=(os.path.expanduser('~/.scribusGenerator.log'),'a','maxBytes=50','backupCount=1')

The tilde without an explicit call to expanduser() was not working in 
Windows... but with it it's working like a charm.

Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list