0

I am trying to convert my current projects from python 2.7 to 3.5. One of the first tasks is configuration of logging. I use a configuration file for flexibility and the date is part of the file name. Below is the code for setting up the file handler that works fine in 2.7

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
# Only one log per day will be created. All messages will be appended to it.
args=("D:\\Logs\\PyLogs\\" + time.strftime("%Y%m%d%H%M%S")+'.log', 'a')

In 3.5 the following error occurs:

configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%Y%m%d%H%M%S")+\'.log\', \'a\')'

Has anyone experience with this? Is there a better way to format the date within the configuration file?

2
  • I'm surprised this worked at all in 2.7. Why not use a TimedRotatingFileHandler though? class=TimedRotatingFileHandler, with when='D'. Commented Jul 29, 2016 at 10:28
  • I didn't use a TimeRotatingFileHandler, because it didn't do what I wanted, but thanks for suggestion. Commented Aug 2, 2016 at 10:03

1 Answer 1

1

similar subject as this post: Configparser and string with %

I think you may need the substitution for %

Sign up to request clarification or add additional context in comments.

3 Comments

I looked at that before and it didn't offer any help
Doubling the % did not fix it?
Actually it did fix it. I had not tried it because I assumed that it would simply shift the problem from the configparser to time.strftime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.