New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logger.config.fileConfig cant cope with files starting with an 'r' on windows #63727
Comments
When attempting to use a config file with logging to set up a series of loggers in a script, when running on windows, if the config file name starts with an 'r' then the script fails with the following error:- File "C:\Users\simon\Documents\python dev\RepositoryChainPkg\FileLogger.py", line 45, in fileConfig The same script works perfectly on linux and solaris. Points to note, the config filename (and path) is listed in the error as:- 'C:\\Users\\simon\repositoryChainLogging\repo_log.log' Yet when it is passed to logging\config.py as parameter fname in function fileConfig it is:- In other words the path passed in by the script is correctly seperated and escaped by os.path functions. However in _install_handlers (line 133 of logging\config.py) the args = eval(args, vars(logging))line (154) gets the path back in this tuple:- (b'C:\\Users\\snaish.BRIGHTON\repositoryChainLogging\repo_log.log', b'a', 131072, Where it has clearly lost some of the escaping, rendering the path useless, since \r is a control character, and therefore invalidates the path. Therefore at the moment it is impossible to use logging config fiels beginning with r onw windows at the moment. |
It looks like you need to use double-backslashes everywhere in your path, or use single backslashes and raw strings (r""). |
I am using double backslashes in my path. But logger\config.py is losing them, please re-read the issue description, logger\config.py is part of the python libraries! |
Apologies for reading too quickly. I've reopened this. |
Can you provide a small, stand-alone program that demonstrates the problem? In particular, I want to see how this filename is provided to logging. |
Example proggie. It writes its own config file (really_cool_logging.conf), then attempts to read it, all to ~/testlog If you inherit from the class FileLogger with any other class you get instant access to self.log.<any logger command> which will write debug and above to ~/testlog/really_cool_logging.log, and info and above to the console. Which is really handy when you have a lot of command scripts that you want to log to one place. |
Updated TestFileLogger, missed a line out in my rush to get you something, sorry! |
And again. Damn! |
Simon, in your code you build the config file with '''... The logging module uses eval() to process the args tuple, and a filename containing a bashlash will not roundtrip that way. Have a look at the .conf file, it contains something like args=('whatever\testlog\really_cool_logging.log', 'a', 131072, 10) when it should be args=('whatever\\testlog\\really_cool_logging.log', 'a', 131072, 10) To fix this you should drop the quote chars and use the string representation of the filename: '''... In short: I think Eric was right with initial assumption. |
Hi Peter, Oh well spotted! Fair enough, but that is seriously not obvious, thanks. Si |
Thanks, Peter. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: