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


Ignore:
Timestamp:
Nov 9, 2026, 12:15:48 PM (6 hours ago)
Author:
stuerze
Message:

Structured logging improved

File:
1 edited

Legend:

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

    r11179 r11185  
    7373  _logFileStructured  = 0;
    7474  _logFormatStructured = t_logRecord::json;
     75  _logLevelStructured  = t_logRecord::debug;
    7576  _rawFile     = 0;
    7677  _caster      = 0;
    … …  
    149150  }
    150151  slotLogRecord(t_logRecord::fromMessage(msg), showOnScreen);
     152}
     153
     154// Write a Program Message of a component with an explicit level
     155////////////////////////////////////////////////////////////////////////////
     156void t_bncCore::message(const QByteArray& msg, bool showOnScreen, const QByteArray& component,
     157                        t_logRecord::e_level level) {
     158  if (msg.isEmpty()) {
     159    return;
     160  }
     161  slotLogRecord(t_logRecord::message(level, msg, component), showOnScreen);
     162}
     163
     164// Write a Program Message of a component
     165////////////////////////////////////////////////////////////////////////////
     166void t_bncCore::message(const QByteArray& msg, bool showOnScreen, const QByteArray& component) {
     167  if (msg.isEmpty()) {
     168    return;
     169  }
     170  slotLogRecord(t_logRecord::fromMessage(msg, component), showOnScreen);
    151171}
    152172
    … …  
    199219      _logFormatStructured = t_logRecord::formatFromString(
    200220                               settings.value("logFormatStructured").toString());
     221      _logLevelStructured  = t_logRecord::levelFromString(
     222                               settings.value("logLevelStructured").toString());
    201223      _logFileStructured = new QFile(structName + "_" + currDate.toString("yyMMdd"));
    202224      if (!_logFileStructured->open(append ? (QIODevice::WriteOnly | QIODevice::Append)
    … …  
    219241  }
    220242
    221   if (_logFileStructured) {
     243  if (_logFileStructured && rec._level >= _logLevelStructured) {
    222244    _logFileStructured->write(rec.encode(_logFormatStructured, currDateTime) + "\n");
    223245    _logFileStructured->flush();
    … …  
    232254#ifdef BNC_DEBUG_BCE
    233255  if (eph->checkState() == t_eph::unhealthy) {
    234     messagePrivate(t_logRecord::fromMessage(QString("%1: UNHEALTHY %2:%3")
     256    messagePrivate(t_logRecord::debugMessage("bce", QString("%1: UNHEALTHY %2:%3")
    235257                   .arg(eph->receptStaID())
    236258                   .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
    … …  
    238260  }
    239261  if (eph->checkState() == t_eph::bad) {
    240     messagePrivate(t_logRecord::fromMessage(QString("%1: WRONG %2:%3")
     262    messagePrivate(t_logRecord::debugMessage("bce", QString("%1: WRONG %2:%3")
    241263                   .arg(eph->receptStaID())
    242264                   .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
    … …  
    244266  }
    245267  if (eph->checkState() == t_eph::outdated) {
    246     messagePrivate(t_logRecord::fromMessage(QString("%1: OUTDATED %2:%3")
     268    messagePrivate(t_logRecord::debugMessage("bce", QString("%1: OUTDATED %2:%3")
    247269                   .arg(eph->receptStaID())
    248270                   .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
    … …  
    633655                      + QByteArray::number(_portEph) + ": "
    634656                      + _serverEph->errorString();
    635       slotMessage(message.toLatin1(), true);
     657      slotLogRecord(t_logRecord::message(t_logRecord::error, message.toLatin1(), "bnc"), true);
    636658    }
    637659    connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
    … …  
    653675                      + QByteArray::number(_portCorr) + ": "
    654676                      + _serverCorr->errorString();
    655       slotMessage(message.toLatin1(), true);
     677      slotLogRecord(t_logRecord::message(t_logRecord::error, message.toLatin1(), "bnc"), true);
    656678    }
    657679    connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
Note: See TracChangeset for help on using the changeset viewer.