Skip to content

Commit

Permalink
enh: NMLogger: add text-only logging to NMLogger for tracking child p…
Browse files Browse the repository at this point in the history
…rocess messages

  - add signal sendLogTxtMsg(...) to NMLogger

shared/NMLogger.cpp
shared/NMLogger.h
  • Loading branch information
heralex committed Feb 3, 2025
1 parent 8c0bb1a commit 1e083b2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 35 deletions.
79 changes: 46 additions & 33 deletions shared/NMLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ NMLogger::logProvN(const NMProvConcept &concept,

msg += ")\n";

if (mMPIRank == 0)
//if (mMPIRank == 0)
{
emit sendProvN(msg);
}
Expand All @@ -128,10 +128,12 @@ NMLogger::processLogMsg(const QString &time, LogEventType type, const QString &m
}

QString logmsg = msg;
QString txtmsg = msg;
// each message its own line unless we specifiy bForceNewLine = false!
if (bForceNewLine && msg.at(msg.size()-1) != '\n')
{
logmsg = QString("%1 \n").arg(msg);
txtmsg = logmsg;
}

if (mbHtml)
Expand Down Expand Up @@ -168,43 +170,54 @@ NMLogger::processLogMsg(const QString &time, LogEventType type, const QString &m
logmsg = QString("%1 DEBUG: %2").arg(time).arg(logmsg);
}
break;
default:
logmsg = QString("<b>%1</b>").arg(logmsg);
break;
}
}
else
{
switch(type)

//if (mMPIRank == 0)
{
case NM_LOG_INFO:
if (!bForceNewLine)
{
logmsg = QString("%1 ").arg(logmsg);
}
else
{
logmsg = QString("%1 INFO: %2").arg(time).arg(logmsg);
}
break;
case NM_LOG_WARN:
logmsg = QString("%1 WARNING: %2").arg(time).arg(logmsg);
break;
case NM_LOG_ERROR:
logmsg = QString("%1 ERROR: %2").arg(time).arg(logmsg);
break;
case NM_LOG_DEBUG:
if (!bForceNewLine)
{
logmsg = QString("%1 ").arg(logmsg);
}
else
{
logmsg = QString("%1 DEBUG: %2").arg(time).arg(logmsg);
}
break;
emit sendLogMsg(logmsg);
}
}

if (mMPIRank == 0)
// we always send a text message for log files
switch(type)
{
case NM_LOG_INFO:
if (!bForceNewLine)
{
txtmsg = QString("%1 ").arg(txtmsg);
}
else
{
txtmsg = QString("%1 INFO: %2").arg(time).arg(txtmsg);
}
break;
case NM_LOG_WARN:
txtmsg = QString("%1 WARNING: %2").arg(time).arg(txtmsg);
break;
case NM_LOG_ERROR:
txtmsg = QString("%1 ERROR: %2").arg(time).arg(txtmsg);
break;
case NM_LOG_DEBUG:
if (!bForceNewLine)
{
txtmsg = QString("%1 ").arg(txtmsg);
}
else
{
txtmsg = QString("%1 DEBUG: %2").arg(time).arg(txtmsg);
}
break;
default:
txtmsg = QString("%1").arg(logmsg);
break;
}


//if (mMPIRank == 0)
{
emit sendLogMsg(logmsg);
emit sendLogTxtMsg(txtmsg);
}
}
7 changes: 5 additions & 2 deletions shared/NMLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class NMLogger : public QObject
NM_LOG_INFO = 1,
NM_LOG_WARN = 2,
NM_LOG_ERROR = 3,
NM_LOG_NOLOG = 4

NM_LOG_NOLOG = 4,
} LogEventType;

typedef enum {
Expand Down Expand Up @@ -59,7 +58,11 @@ class NMLogger : public QObject
LogEventType getLogLevel(void){return mLogLevel;}

signals:
// html message for display in GUI
void sendLogMsg(const QString& msg);
// text message for log files
void sendLogTxtMsg(const QString& msg);
// provN logging
void sendProvN(const QString& provLog);

public slots:
Expand Down

0 comments on commit 1e083b2

Please sign in to comment.