dept2 / CuteLogger

Logger: simple, convinient and thread safe logger for Qt-based C++ apps
GNU Lesser General Public License v2.1
145 stars 97 forks source link

Rolling logfile when starting if needed #12

Open pnlarsson opened 9 years ago

pnlarsson commented 9 years ago

The rolling is working if the application is not shutdown over night (for daily).

Solved by getting the modification time from file if it exists when starting the application and using it instead of now.

cyberbobs commented 8 years ago

Sorry, but I don't actually understand, what is happening in the changes you submitted. Could you please describe, why must we use the currently opened log file last modification date and time instead of current date? The modification datetime will be anyway updated to meet the current datetime after writing the log record once :)

pnlarsson commented 8 years ago

If you use daily and stop app in the night and start it in the morning - it didn't roll the logs.

raccoonmonk commented 8 years ago

I need this change, it's very useful. But still your commit has a problem - the last append goes to the old logfile.

LeeGaning commented 2 years ago

I need this change, it's very useful. But still your commit has a problem - the last append goes to the old logfile. this will be work.

QDateTime now;
if (m_rollOverTime.isNull()) {
QFileInfo fileInfo = QFileInfo(fileName());
if (fileInfo.isFile()) {
now = fileInfo.lastModified();
}
}
if (!now.isValid() || now > QDateTime::currentDateTime()) {
now = QDateTime::currentDateTime();
}