Logging help

koranthala koranthala at gmail.com
Thu Jan 22 10:40:39 EST 2009


On Jan 22, 2:14 pm, Vinay Sajip <vinay_sa... at yahoo.co.uk> wrote:
> On Jan 22, 6:49 am,koranthala<koranth... at gmail.com> wrote:
>
> > I understand Vinay. But my point is that I wanted a mechanism to
> > rotate the log files based on data - i.e. today one log, tomorrow
>
> Did you mean "based on date"?
>
> > another. This is easier because when trouble tickets are raised, users
> > mention that X failed at this time.
> > Now, timedrotatingfilehandler does it - but only if the program is
> > running the whole length of time.
> > My tool is invoked by a cron job - so the program runs, then stops
> > again and again.
>
> If you just want a log file whose name is date-based, you don't need a
> rotating file handler. Compute the file name from the date and use the
> API to create a FileHandler specifying that file name, and add it to
> your logger. For example:
>
> import logging, time
>
> logging.basicConfig(level=logging.DEBUG, filename=time.strftime("/path/
> to/my/logs/myapp-%Y-%m-%d-%H%M.log", time.localtime()), filemode="w")
> logging.debug("Hello, world!")
>
> Hopefully you can adapt this snippet to your needs.
>
> Regards,
>
> Vinay Sajip

Thank you very much Vinay. You have been extremely helpful.
This was my first design - but then I found that log system was taking
up quite a huge chunk of the memory.
That is why I went to rotating file handler.
Anyways, now I have modified doRollover to append if file is there,
so, for me it is working.
What I was thinking was such an option in the basic logging system
might be of good help.
Again, Vinay, Thank you very much. You were extremely helpful.



More information about the Python-list mailing list