SergiusTheBest / plog

Portable, simple and extensible C++ logging library
MIT License
2.19k stars 385 forks source link

Roll log on application start #259

Closed stiggy87 closed 1 year ago

stiggy87 commented 1 year ago

I'm using PLOG as a way to track user interactions in my application, so it's separate from the main log. What I would like is that if the program is closed/re-opened that the second log is rolled at start. Is there a way to do that, or would it be a custom FileAppender?

SergiusTheBest commented 1 year ago

Yes, there is a way. Call rollLogFiles from RollingFileAppender at the beginning:

plog::RollingFileAppender<plog::TxtFormatter> fileAppender("file.log", 1000000, 1); 
fileAppender.rollLogFiles();

Thus you'll have one log file written from the start every time a program is launched.

stiggy87 commented 1 year ago

Great! This works perfectly for what I want, even if I set the maxFiles to another value.

Thanks!