| 104 | } |
| 105 | |
| 106 | void Logger::refreshLogFile() |
| 107 | { |
| 108 | QDir folder; |
| 109 | if(!folder.exists(logFolder)) |
| 110 | folder.mkpath(logFolder); |
| 111 | folder.setPath(logFolder); |
| 112 | |
| 113 | QRegularExpression re("\\d{4}-\\d{2}-\\d{2}"); |
| 114 | qint64 curTime = QDateTime::currentDateTime().toSecsSinceEpoch(); |
| 115 | for (QFileInfo fileInfo : folder.entryInfoList()) |
| 116 | { |
| 117 | if (fileInfo.isFile() && fileInfo.suffix().toLower()=="log") |
| 118 | { |
| 119 | auto match = re.match(fileInfo.fileName()); |
| 120 | if (!match.hasMatch() || match.capturedStart(0) != 0) continue; |
| 121 | //if(re.indexIn(fileInfo.fileName())!=0) continue; |
| 122 | int logTime = QDateTime::fromString(match.captured(0), "yyyy-MM-dd").toSecsSinceEpoch(); |
| 123 | if(curTime - logTime > 3*24*3600) |
| 124 | { |
| 125 | folder.remove(fileInfo.fileName()); |
| 126 | log(LogType::APP, QString("Remove Log File: %1").arg(fileInfo.fileName())); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | void Logger::writeLogFile(Logger::LogType type) |
| 133 | { |