Changeset 11179 in ntrip for trunk/BNC/src/bnccore.cpp


Ignore:
Timestamp:
Nov 6, 2026, 4:05:20 PM (28 hours ago)
Author:
stuerze
Message:

structuered logging is added and bug is fixed in SP3 file writing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/bnccore.cpp

    r11136 r11179  
    7171  _logFile     = 0;
    7272  _logStream   = 0;
     73  _logFileStructured  = 0;
     74  _logFormatStructured = t_logRecord::json;
    7375  _rawFile     = 0;
    7476  _caster      = 0;
    … …  
    103105  qRegisterMetaType< QVector<double> >      ("QVector<double>");
    104106  qRegisterMetaType<bncTime>                ("bncTime");
     107  qRegisterMetaType<t_logRecord>            ("t_logRecord");
    105108  qRegisterMetaType<t_ephGPS>               ("t_ephGPS");
    106109  qRegisterMetaType<t_ephGlo>               ("t_ephGlo");
    … …  
    122125  delete _logStream; _logStream = 0;
    123126  delete _logFile;   _logFile   = 0;
     127  delete _logFileStructured; _logFileStructured = 0;
    124128  qDeleteAll(_ephFiles);
    125129  delete _serverEph;
    … …  
    144148    return;
    145149  }
     150  slotLogRecord(t_logRecord::fromMessage(msg), showOnScreen);
     151}
     152
     153// Write a Program Message with structured fields (structured logfile);
     154// the classic logfile and the screen get the text rec._msg
     155////////////////////////////////////////////////////////////////////////////
     156void t_bncCore::slotLogRecord(t_logRecord rec, bool showOnScreen) {
     157  if (rec._msg.isEmpty()) {
     158    return;
     159  }
    146160  QMutexLocker locker(&_mutexMessage);
    147161
    148   messagePrivate(msg);
    149   emit newMessage(msg, showOnScreen);
     162  messagePrivate(rec);
     163  emit newMessage(rec._msg, showOnScreen);
    150164}
    151165
    152166// Write a Program Message (private, no lock)
    153167////////////////////////////////////////////////////////////////////////////
    154 void t_bncCore::messagePrivate(const QByteArray& msg) {
    155 
    156   // First time resolve the log file name
    157   // ------------------------------------
    158   QDate currDate = currentDateAndTimeGPS().date();
     168void t_bncCore::messagePrivate(const t_logRecord& rec) {
     169
     170  // First time resolve the log file names
     171  // -------------------------------------
     172  QDateTime currDateTime = currentDateAndTimeGPS();
     173  QDate currDate = currDateTime.date();
    159174  if (_logFileFlag == 0 || _fileDate != currDate) {
    160175    delete _logStream; _logStream = 0;
    161176    delete _logFile;   _logFile   = 0;
     177    delete _logFileStructured; _logFileStructured = 0;
    162178    _logFileFlag = 1;
     179    _fileDate = currDate;
    163180    bncSettings settings;
     181    bool append = (Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked);
    164182    QString logFileName = settings.value("logFile").toString();
    165183    if ( !logFileName.isEmpty() ) {
    … …  
    167185      _logFile = new QFile(logFileName + "_" +
    168186                          currDate.toString("yyMMdd").toLatin1().data());
    169       _fileDate = currDate;
    170       if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
     187      if (append) {
    171188        _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
    172189      }
    … …  
    177194      _logStream->setDevice(_logFile);
    178195    }
     196    QString structName = settings.value("logFileStructured").toString();
     197    if ( !structName.isEmpty() ) {
     198      expandEnvVar(structName);
     199      _logFormatStructured = t_logRecord::formatFromString(
     200                               settings.value("logFormatStructured").toString());
     201      _logFileStructured = new QFile(structName + "_" + currDate.toString("yyMMdd"));
     202      if (!_logFileStructured->open(append ? (QIODevice::WriteOnly | QIODevice::Append)
     203                                           : QIODevice::WriteOnly)) {
     204        delete _logFileStructured; _logFileStructured = 0;
     205      }
     206    }
    179207  }
    180208
    181209  if (_logStream) {
    182     QByteArray msgLocal = msg;
    183     if (msg.indexOf('\n') == 0) {
     210    QByteArray msgLocal = rec._msg;
     211    if (rec._msg.indexOf('\n') == 0) {
    184212      *_logStream << "\r\n";
    185       msgLocal = msg.mid(1);
    186     }
    187     *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
     213      msgLocal = rec._msg.mid(1);
     214    }
     215    *_logStream << currDateTime.toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
    188216    *_logStream << msgLocal.data() << "\r\n";
    189217    _logStream->flush();
    190218    _logFile->flush();
     219  }
     220
     221  if (_logFileStructured) {
     222    _logFileStructured->write(rec.encode(_logFormatStructured, currDateTime) + "\n");
     223    _logFileStructured->flush();
    191224  }
    192225}
    … …  
    199232#ifdef BNC_DEBUG_BCE
    200233  if (eph->checkState() == t_eph::unhealthy) {
    201     messagePrivate(QString("%1: UNHEALTHY %2:%3")
     234    messagePrivate(t_logRecord::fromMessage(QString("%1: UNHEALTHY %2:%3")
    202235                   .arg(eph->receptStaID())
    203236                   .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
    204                    .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
     237                   .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
    205238  }
    206239  if (eph->checkState() == t_eph::bad) {
    207     messagePrivate(QString("%1: WRONG %2:%3")
     240    messagePrivate(t_logRecord::fromMessage(QString("%1: WRONG %2:%3")
    208241                   .arg(eph->receptStaID())
    209242                   .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
    210                    .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
     243                   .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
    211244  }
    212245  if (eph->checkState() == t_eph::outdated) {
    213     messagePrivate(QString("%1: OUTDATED %2:%3")
     246    messagePrivate(t_logRecord::fromMessage(QString("%1: OUTDATED %2:%3")
    214247                   .arg(eph->receptStaID())
    215248                   .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
    216                    .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
     249                   .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
    217250  }
    218251#endif
Note: See TracChangeset for help on using the changeset viewer.