Logger: simple, convinient and thread safe logger for Qt applications
Please update to the current version of Logger. As of commit c7d9a27 [gitorious.org] QDebug header is included into Logger.h.
How to I destroy this logger object and reinstantiate it without existing the application. Say I have three push buttons (1, 2, 3). I want to instantiate when button 1 is pressed. and use LOG_INFO macro when button 2 is pressed. Flush the data to the file when button 3 is pressed and destroy the object. Re-instantiate the class when button 1 is pressed again without closing the application.
In my application we never exit the application it contoneously runs. I am looking for a way to instantiate the class, use log_info, detroy the object and then reinstantiate.
Well, I definitely need to ask a question here: why do you need to manually instantiate and destroy Logger?
This library is created as singleton without any visible initialization by design. Its main object is automatically created on the first Logger::* static function or macro call. As you can see in Logger.cpp [gitorious.org] the object is automatically destroyed after the application have been closed (using the qAddPostRoutine function).
So, once again: why do you want to do manually the thing that is done automatically? :)
IMO the most correct way to implement a log rotation is to create separate log files for every week/day/hour (choose yours interval) and to automatically remove older logs becoming obsolete. For example, Apache web server logging is organized in such a way. We’ve implemented that kind of log rotation for one of our projects using Logger some time ago, but I’ve never published those classes. The problem is I can’t share the source because of some licensing restrictions (it was created by another developer working on a commercial project).
Anyone interested in implementing that kind of functionality (and adding it to logger mainstream code) could easily contact me via email or simply post a merge request on gitorious.