Changeset 11185 in ntrip for trunk/BNC/src/bnclog.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/bnclog.cpp

    r11179 r11185  
    2424namespace {
    2525
    26 QMutex          stationMutex;
    27 QSet<QByteArray> stations;
     26QMutex          streamMutex;
     27QSet<QByteArray> streams;
    2828
    2929// text as UTF-8 (BNC's messages are Latin-1)
    … …  
    9797// Envelope of a plain text message
    9898////////////////////////////////////////////////////////////////////////////
    99 t_logRecord t_logRecord::fromMessage(const QByteArray& msg) {
    100   t_logRecord rec(info, "bnc", "message", "", msg);
    101 
    102   // station: first token of the text, if it is a known station name
     99t_logRecord t_logRecord::fromMessage(const QByteArray& msg, const QByteArray& component) {
     100  t_logRecord rec(info, component, "message", "", msg);
     101
     102  // stream: first token of the text, if it is a known stream or PPP station
    103103  int end = 0;
    104104  while (end < msg.size() && msg[end] != ':' && msg[end] != ' ' && msg[end] != '(') {
    … …  
    107107  if (end > 0) {
    108108    QByteArray token = msg.left(end);
    109     QMutexLocker locker(&stationMutex);
    110     if (stations.contains(token)) {
    111       rec._station = token;
     109    QMutexLocker locker(&streamMutex);
     110    if (streams.contains(token)) {
     111      rec._stream = token;
    112112    }
    113113  }
    … …  
    136136}
    137137
     138// Plain text message with an explicit level
     139////////////////////////////////////////////////////////////////////////////
     140t_logRecord t_logRecord::message(e_level level, const QByteArray& msg,
     141                                 const QByteArray& component) {
     142  t_logRecord rec = fromMessage(msg, component);
     143  rec._level = level;
     144  return rec;
     145}
     146
     147// Message of a BNC_DEBUG_* build
     148////////////////////////////////////////////////////////////////////////////
     149t_logRecord t_logRecord::debugMessage(const QByteArray& component, const QByteArray& msg) {
     150  t_logRecord rec = fromMessage(msg, component);
     151  rec._level = debug;
     152  return rec;
     153}
     154
    138155//
    139156////////////////////////////////////////////////////////////////////////////
    … …  
    196213const char* t_logRecord::levelString(e_level level) {
    197214  switch (level) {
     215    case debug:   return "debug";
    198216    case warning: return "warning";
    199217    case error:   return "error";
    … …  
    210228//
    211229////////////////////////////////////////////////////////////////////////////
    212 void t_logRecord::registerStation(const QByteArray& station) {
    213   if (station.isEmpty()) {
     230t_logRecord::e_level t_logRecord::levelFromString(const QString& str) {
     231  QString ss = str.trimmed().toLower();
     232  if (ss == "info")    return info;
     233  if (ss == "warning") return warning;
     234  if (ss == "error")   return error;
     235  return debug;
     236}
     237
     238//
     239////////////////////////////////////////////////////////////////////////////
     240void t_logRecord::registerStream(const QByteArray& stream) {
     241  if (stream.isEmpty()) {
    214242    return;
    215243  }
    216   QMutexLocker locker(&stationMutex);
    217   stations.insert(station);
     244  QMutexLocker locker(&streamMutex);
     245  streams.insert(stream);
    218246}
    219247
    … …  
    242270  put("component", _component, true);
    243271  put("event",     _event, true);
    244   if (!_station.isEmpty()) {
    245     put("station", _station, true);
     272  if (!_stream.isEmpty()) {
     273    put("stream", _stream, true);
    246274  }
    247275  all += _fields;
Note: See TracChangeset for help on using the changeset viewer.