I have a logging system which basically is a fancy way to write my data to std :: clog in safe streaming mode.
I also redirect std::clog
to the file as follows:
int main() {
std::ofstream logfile(config::logname, std::ios::app);
std::streambuf *const old_buffer = std::clog.rdbuf(logfile.rdbuf());
std::clog.rdbuf(old_buffer);
}
This works fine ... however, my application also creates a very large number of logs. I was wondering what would be a good way to rotate my log files correctly. Is there a safe way to switch a file using the cron task? I think no.
The only thing I can think of would definitely work if I myself opened the application for a new file and redirected rdbuf clog to it while holding the log mutexes. But this seems like a cheap solution, and I will need to check if it is time to rotate the magazines often so that they are effective. There has to be a better way.
source
share