Luke
Luke

Reputation: 7099

Python change logfile location at runtime

I have a logging.config file that specifies handlers outputting logs to the console and to a file. How would I go about changing the file location of the file handler at runtime but keeping all of the formatting, etc.

Upvotes: 3

Views: 1985

Answers (1)

Luke
Luke

Reputation: 7099

Here's how I found out how to do it. Under [handler_file] add this line for the output file:

args=('%(logfilename)s',)

Then when initializing logger specify the log file location like so:

logging.config.fileConfig('logging.config',
                          defaults={'logfilename': '/path/to/log/file'})

Upvotes: 5

Related Questions