diff --git a/Conf.cpp b/Conf.cpp index 4036699..fd3c0b0 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -82,6 +82,7 @@ m_height(0), m_location(), m_description(), m_url(), +m_logMQTTLevel(0U), m_logDisplayLevel(0U), m_logFileLevel(0U), m_logFilePath(), @@ -514,6 +515,8 @@ bool CConf::read() m_logFilePath = value; else if (::strcmp(key, "FileRoot") == 0) m_logFileRoot = value; + else if (::strcmp(key, "MQTTLevel") == 0) + m_logMQTTLevel = (unsigned int)::atoi(value); else if (::strcmp(key, "FileLevel") == 0) m_logFileLevel = (unsigned int)::atoi(value); else if (::strcmp(key, "DisplayLevel") == 0) @@ -1244,6 +1247,11 @@ std::string CConf::getURL() const return m_url; } +unsigned int CConf::getLogMQTTLevel() const +{ + return m_logMQTTLevel; +} + unsigned int CConf::getLogDisplayLevel() const { return m_logDisplayLevel; diff --git a/Conf.h b/Conf.h index 29f01e4..f7de0b3 100644 --- a/Conf.h +++ b/Conf.h @@ -50,6 +50,7 @@ public: std::string getURL() const; // The Log section + unsigned int getLogMQTTLevel() const; unsigned int getLogDisplayLevel() const; unsigned int getLogFileLevel() const; std::string getLogFilePath() const; @@ -395,6 +396,7 @@ private: std::string m_description; std::string m_url; + unsigned int m_logMQTTLevel; unsigned int m_logDisplayLevel; unsigned int m_logFileLevel; std::string m_logFilePath; diff --git a/Log.cpp b/Log.cpp index 58f8840..fee5304 100644 --- a/Log.cpp +++ b/Log.cpp @@ -35,6 +35,8 @@ CMQTTPublisher* m_mqtt = NULL; +static unsigned int m_mqttLevel = 2U; + static unsigned int m_fileLevel = 2U; static std::string m_filePath; static std::string m_fileRoot; @@ -127,10 +129,11 @@ bool LogOpen() return logOpenNoRotate(); } -bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate) +bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int mqttLevel, bool rotate) { m_filePath = filePath; m_fileRoot = fileRoot; + m_mqttLevel = mqttLevel; m_fileLevel = fileLevel; m_displayLevel = displayLevel; m_daemon = daemon; @@ -174,7 +177,7 @@ void Log(unsigned int level, const char* fmt, ...) va_end(vl); - if (m_mqtt != NULL) + if (m_mqtt != NULL && level >= m_mqttLevel && m_mqttLevel != 0U) m_mqtt->publish("log", buffer); if (level >= m_fileLevel && m_fileLevel != 0U) { diff --git a/Log.h b/Log.h index ae95b60..96c3f13 100644 --- a/Log.h +++ b/Log.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2020,2022 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ extern void Log(unsigned int level, const char* fmt, ...); -extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, bool rotate); +extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int mqttLevel, bool rotate); extern void LogFinalise(); #endif diff --git a/MMDVM.ini b/MMDVM.ini index 8aef68a..31a8a59 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -23,6 +23,7 @@ URL=www.google.co.uk [Log] # Logging levels, 0=No logging +MQTTLevel=1 DisplayLevel=1 FileLevel=1 FilePath=. diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 5da6a7c..83f10df 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -271,9 +271,9 @@ int CMMDVMHost::run() #endif #if !defined(_WIN32) && !defined(_WIN64) - ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate()); + ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogMQTTLevel(), m_conf.getLogFileRotate()); #else - ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate()); + ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogMQTTLevel(), m_conf.getLogFileRotate()); #endif if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to open the log file\n"); diff --git a/RemoteCommand.cpp b/RemoteCommand.cpp index 0e8918d..7443a0e 100644 --- a/RemoteCommand.cpp +++ b/RemoteCommand.cpp @@ -57,7 +57,7 @@ m_port(port) { CUDPSocket::startup(); - ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U, false); + ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U, 2U, false); } CRemoteCommand::~CRemoteCommand()