I am using the "logging" module - in a simple manner - to log activities of a daemon process to a file. The process is expected to be running for days - and I would like the log filename to be different for each date -dproc.yyyy-mm-dd.log - e.g.
In my code I periodically call a set logging function:-
- Code: Select all
def setLogging( logdir ):
Log file is <logdir>/dproc.yyyy-mm-dd.log
today = datetime.date.today()
log_dt = str(today)
logfile = logdir + "/dproc." + log_dt + ".log"
logging.basicConfig(filename=logfile, format='%(asctime)s %(message)s', level=logging.INFO)
However this does NOT change when the date changes. I now understand that logging.basicConfig() has no effect once a default handler is setup and active.
Questions : Can I change the filename in some way - and if so how? I suppose a supplementary question is - should I be using another approach? (I'm not particular keen on setting up log rotation unless it can be by date).