Changeset 11187 in ntrip for trunk/BNC/src/bnccore.cpp
- Timestamp:
- Nov 9, 2026, 5:37:55 PM (less than one hour ago)
- File:
-
- 1 edited
-
trunk/BNC/src/bnccore.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/src/bnccore.cpp
r11185 r11187 43 43 #include <QMessageBox> 44 44 #include <cmath> 45 #ifndef Q_OS_WIN 46 #include <sys/stat.h> 47 #endif 45 48 46 49 #include "bnccore.h" … … 72 75 _logStream = 0; 73 76 _logFileStructured = 0; 77 _logStructuredInit = false; 74 78 _logFormatStructured = t_logRecord::json; 75 79 _logLevelStructured = t_logRecord::debug; … … 195 199 delete _logStream; _logStream = 0; 196 200 delete _logFile; _logFile = 0; 197 delete _logFileStructured; _logFileStructured = 0;198 201 _logFileFlag = 1; 199 202 _fileDate = currDate; … … 214 217 _logStream->setDevice(_logFile); 215 218 } 216 QString structName = settings.value("logFileStructured").toString(); 217 if ( !structName.isEmpty() ) { 218 expandEnvVar(structName); 219 } 220 221 // Structured logfile: one endless file (rotation by external tools) 222 // --------------------------------------------------------------- 223 if (!_logStructuredInit) { 224 _logStructuredInit = true; 225 bncSettings settings; 226 _logFileStructuredName = settings.value("logFileStructured").toString(); 227 if (!_logFileStructuredName.isEmpty()) { 228 expandEnvVar(_logFileStructuredName); 219 229 _logFormatStructured = t_logRecord::formatFromString( 220 230 settings.value("logFormatStructured").toString()); 221 231 _logLevelStructured = t_logRecord::levelFromString( 222 232 settings.value("logLevelStructured").toString()); 223 _logFileStructured = new QFile(structName + "_" + currDate.toString("yyMMdd")); 224 if (!_logFileStructured->open(append ? (QIODevice::WriteOnly | QIODevice::Append) 225 : QIODevice::WriteOnly)) { 226 delete _logFileStructured; _logFileStructured = 0; 227 } 228 } 233 openLogFileStructured(); 234 } 235 } 236 else if (!_logFileStructuredName.isEmpty() && _logStructuredCheck.hasExpired(1000)) { 237 openLogFileStructured(); // reopens only if the file was moved or removed 229 238 } 230 239 … … 244 253 _logFileStructured->write(rec.encode(_logFormatStructured, currDateTime) + "\n"); 245 254 _logFileStructured->flush(); 255 } 256 } 257 258 // Open the structured logfile, or reopen it after an external rotation 259 // (logrotate without copytruncate moves the file and the old one must be 260 // released); always appending, also after copytruncate 261 //////////////////////////////////////////////////////////////////////////// 262 void t_bncCore::openLogFileStructured() { 263 _logStructuredCheck.start(); 264 if (_logFileStructured) { 265 bool same = _logFileStructured->exists(); 266 #ifndef Q_OS_WIN 267 if (same) { 268 struct stat stPath, stOpen; 269 same = (stat(QFile::encodeName(_logFileStructuredName).constData(), &stPath) == 0 && 270 fstat(_logFileStructured->handle(), &stOpen) == 0 && 271 stPath.st_dev == stOpen.st_dev && stPath.st_ino == stOpen.st_ino); 272 } 273 #endif 274 if (same) { 275 return; 276 } 277 delete _logFileStructured; _logFileStructured = 0; 278 } 279 _logFileStructured = new QFile(_logFileStructuredName); 280 if (!_logFileStructured->open(QIODevice::WriteOnly | QIODevice::Append)) { 281 delete _logFileStructured; _logFileStructured = 0; 246 282 } 247 283 }
Note:
See TracChangeset
for help on using the changeset viewer.
