From 1e083b2f84dd8062eb6a481b86834edb6ca37edc Mon Sep 17 00:00:00 2001 From: Alex Herzig Date: Tue, 4 Feb 2025 05:39:07 +1300 Subject: [PATCH] enh: NMLogger: add text-only logging to NMLogger for tracking child process messages - add signal sendLogTxtMsg(...) to NMLogger shared/NMLogger.cpp shared/NMLogger.h --- shared/NMLogger.cpp | 79 ++++++++++++++++++++++++++------------------- shared/NMLogger.h | 7 ++-- 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/shared/NMLogger.cpp b/shared/NMLogger.cpp index 3def8d7b..c8e00c58 100644 --- a/shared/NMLogger.cpp +++ b/shared/NMLogger.cpp @@ -111,7 +111,7 @@ NMLogger::logProvN(const NMProvConcept &concept, msg += ")\n"; - if (mMPIRank == 0) + //if (mMPIRank == 0) { emit sendProvN(msg); } @@ -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) @@ -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("%1").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); } } diff --git a/shared/NMLogger.h b/shared/NMLogger.h index 3c01bb03..299d7ec0 100644 --- a/shared/NMLogger.h +++ b/shared/NMLogger.h @@ -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 { @@ -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: