Need help in configuration for TimedRotatingFileHandler

Dave Angel davea at ieee.org
Sun Aug 9 17:15:47 EDT 2009


Lokesh wrote:
> Hi,
>
> Need help in configure the TimedRotatingFileHandler from configuration
> file
>
> I have tried with the below code and ended up with the error, code is
> pasted below
> Error - IOError: [Errno 2] No such file or directory: 'G:\\lok_sib\
> \logs\rotate_test'
> [loggers]
> keys=root,simpleExample
>
> [handlers]
> keys=consoleHandler,timedRotatingFileHandler
>
> [formatters]
> keys=simpleFormatter
>
> [logger_root]
> level=DEBUG
> handlers=consoleHandler
>
> [logger_simpleExample]
> level=DEBUG
> handlers=timedRotatingFileHandler
> qualname=simpleExample
> propagate=0
>
> [handler_consoleHandler]
> class=StreamHandler
> level=DEBUG
> formatter=simpleFormatter
> args=(sys.stdout,)
>
> [handler_timedRotatingFileHandler]
> class=handlers.TimedRotatingFileHandler
> level=DEBUG
> formatter=simpleFormatter
> args=("G:\lok_sib\logs\rotate_test", 'midnight', 1)
>
> [formatter_simpleFormatter]
> format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
> datefmt='%Y-%m-%d %H:%M:%S'
>
>
> Thanks or your time
> Regards,
> Lokesh
>
>   
I don't see code there, I see lots of config data, presumably in an .ini 
file.   So I don't know how you're reading it in, and converting it to 
Python variables, but I know where I'd look, based on your error message.

The following line:

args=("G:\lok_sib\logs\rotate_test", 'midnight', 1)

seems to contain a Python string.  But there are unescaped backslashes 
within it.  You can get away with it in two cases, because \l  isn't a 
valid escape sequence.  But in the case of \r, it looks like a newline 
character.

Anyway, all three of those backslashes probably need to be doubled.

args=("G:\\lok_sib\\logs\\rotate_test", 'midnight', 1)

Two other cures that may work, depending on context:   change the backslashes to forward slashes, or use a raw string.

But as I said earlier, you don't show in any way what code is interpreting this line, so it's all just guesswork.

DaveA




More information about the Python-list mailing list