Python Logging - Set Date as Filename : <p>I am working on implementing logging within my Python project and have hit a bit of a snag.  I am trying to set up my logging such that the Handlers, and Formatters are all organized into a configuration file.  What I am trying to do at the moment is to set up my <code>fileHandler</code> such that it will create a log file that looks something like this: <code>YYYY_MM_DD.log</code> obviously with the Y's representing the year, M's representing the month, and D's representing the day.</p>

<p>This is what I have attempted with my config file:</p>

<pre><code>[loggers]
keys=root,MainLogger

[handlers]
keys=fileHandler, consoleHandler

[formatters]
keys=logFormatter, consoleFormatter

[logger_root]
level=DEBUG
handlers=fileHandler

[logger_MainLogger]
level=DEBUG
handlers=fileHandler, consoleHandler
qualname=MainLogger
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=consoleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=logFormatter
args=(datetime.now().strftime('%Y_%m_%d.log'), 'a')

[formatter_logFormatter]
format=%(asctime)s | %(levelname)-8s | %(lineno)04d | %(message)s

[formatter_consoleFormatter]
format=%(asctime)s | %(levelname)-8s | %(fillname)s-%(funcName)s-%(lineno)04d | %message)s
</code></pre>

<p>The file I am using to test the configuration is pretty simple:</p>

<pre><code>import logging
import logging.config

logging.config.fileConfig('logging.conf')
logger = logging.getLogger('MainLogger')
logger.debug("TEST")
</code></pre>

<p>The specific error I am getting at the moment is:</p>

<pre><code>configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%Y_%m_%d.log'), 'a')"
</code></pre>

<p>I've tried changing the <code>%Y</code>, <code>%m</code>, and <code>%d</code> as the error says, but that doesn't fix the problem.  How do I go about setting up the config file so that my log files look the way I want them to?</p>

<p>I should note when I change the filename to <code>test.log</code> everything worked fine, so this is the only error I seem to be having with this.</p>
