473,545 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overriding Logging Config FileHandler Filename

I have a Python logging config file that contains a RotatingFileHan dler
handler. In the args key, I have hard-coded the log filename. Everything
works great.

However, I find that I now need to override this filename at application
runtime. Is there a good way to do this?

Here is a bit of sample code that (hopefully) clarifies my question.

--------------- log.ini -----------------
keys=root,proce ssor

; Lots more stuff here: handlers, formatters, and loggers.......

keys=consoleHan dler,fileHandle r

[handler_fileHan dler]
class=handlers. RotatingFileHan dler
formatter=stand ard
args=('D:\Proje cts\Python\src\ log.log', 'a', 99999, 10)

-------------- mymain.py -----------------
import logging.config

logging.config. fileConfig('log .ini')

# TODO: Override log filename with new name (e.g. 'd:\\logs\\myma in.py.log')

log = logging.getLogg er('mymain')

log.info('START : mymain.py')
log.info('FINIS H: mymain.py')

Kenneth Love

Kenneth Love | Oklahoma Tax Commission
DP Programmer/Analyst | Information Technology
(405) 522 - 5864 | http://www.tax.ok.gov/
Sep 25 '07 #1
1 3633
On Sep 25, 9:15 pm, "Kenneth Love" <kl...@tax.ok.g ovwrote:
I have a Pythonloggingco nfig file that contains a RotatingFileHan dler
handler. In the args key, I have hard-coded the log filename. Everything
works great.

However, I find that I now need to override this filename at application
runtime. Is there a good way to do this?
Are you using the original file name mentioned in the config file at
all? Why and under what conditions do you need to switch? You could
easily do this programmaticall y - have two handlers and when you need
to, remove one from the logger and add the other. I see you are using
a rotating handler, which itself does rollover to new log files every
so often.


Vinay Sajip

Sep 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Thomas Heller | last post by:
I'm about to add some logging calls to a library I have. How can I prevent that the script that uses the library prints 'No handlers could be found for logger "comtypes.client"' when the script runs? I would like to setup the logging so that there is no logging when nothing is configured, and no warning messages are printed. Thomas
by: Tekkaman | last post by:
I'm getting a strange behaviour from the "pathname" and "lineno" formatter mapping keys. Instead of my file and my line number I get: /usr/lib/python2.4/logging/__init__.py as the file, and 1072 as the line number. I set up my config as follows: logBaseConf = { 'level' : logging.DEBUG,
by: Vyacheslav Maslov | last post by:
Hi all! I have many many many python unit test, which are used for testing some remote web service. The most important issue here is logging of test execution process and result. I strongly need following: 1. start/end timestamp for each test case (most important) 2. immediate report about exceptions (stacktrace) 3. it will be nice to...
by: guybenron | last post by:
Hey, I have a sort of petty-neurotic question, I'm kinda pedantic and like to keep my log directories clean, and this thing is bothering me to the point of actually posting a question (couldn't find any post about this..). My application has two types of components: daemons and regular ones that are run every on crontab. Because the log...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.