From 735e7487d3ae662e3aba39db7ee51f0745c1009a Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Wed, 3 Dec 2014 19:57:23 +0200 Subject: [PATCH] Added a preliminary support for dynamic logging level. --- common.h | 10 ++-------- config.c | 5 +++++ config.h | 11 +++++++++++ discover.c | 12 +++++++----- msearch.c | 1 + poller.c | 1 + rtcp.c | 1 + rtp.c | 1 + rtsp.c | 11 ++++++----- satip.c | 19 +++++++++++++++---- server.c | 1 + 11 files changed, 51 insertions(+), 22 deletions(-) diff --git a/common.h b/common.h index 851d2aa..744f66a 100644 --- a/common.h +++ b/common.h @@ -13,15 +13,9 @@ #include #include -#ifdef DEBUG -#define debug(x...) dsyslog("SATIP: " x) +#define error(x...) esyslog("SATIP-ERROR: " x) #define info(x...) isyslog("SATIP: " x) -#define error(x...) esyslog("ERROR: " x) -#else -#define debug(x...) {} -#define info(x...) isyslog("SATIP: " x) -#define error(x...) esyslog("ERROR: " x) -#endif +#define debug(x...) void( SatipConfig.IsLogLevelDebug() ? dsyslog("SATIP: " x) : void() ) #define ELEMENTS(x) (sizeof(x) / sizeof(x[0])) diff --git a/config.c b/config.c index 4825a81..fd1a4b9 100644 --- a/config.c +++ b/config.c @@ -12,6 +12,11 @@ cSatipConfig SatipConfig; cSatipConfig::cSatipConfig(void) : operatingModeM(eOperatingModeLow), +#ifdef DEBUG + logLevelM(eLogLevelMask), +#else + logLevelM(eLogLevelNormal), +#endif eitScanM(1), useBytesM(1) { diff --git a/config.h b/config.h index 9555480..3484a99 100644 --- a/config.h +++ b/config.h @@ -15,6 +15,7 @@ class cSatipConfig { private: unsigned int operatingModeM; + unsigned int logLevelM; unsigned int eitScanM; unsigned int useBytesM; int disabledSourcesM[MAX_DISABLED_SOURCES_COUNT]; @@ -29,6 +30,12 @@ public: eOperatingModeHigh, eOperatingModeCount }; + enum { + eLogLevelNormal = 0x00, + eLogLevelDebug = 0x01, + eLogLevelExtra = 0x02, + eLogLevelMask = 0x0F + }; cSatipConfig(); unsigned int GetOperatingMode(void) const { return operatingModeM; } bool IsOperatingModeOff(void) const { return (operatingModeM == eOperatingModeOff); } @@ -36,6 +43,9 @@ public: bool IsOperatingModeNormal(void) const { return (operatingModeM == eOperatingModeNormal); } bool IsOperatingModeHigh(void) const { return (operatingModeM == eOperatingModeHigh); } void ToggleOperatingMode(void) { operatingModeM = (operatingModeM + 1) % eOperatingModeCount; } + unsigned int GetLogLevel(void) const { return logLevelM; } + bool IsLogLevelDebug(void) const { return (logLevelM & eLogLevelDebug); } + bool IsLogLevelExtra(void) const { return (logLevelM & eLogLevelExtra); } unsigned int GetEITScan(void) const { return eitScanM; } unsigned int GetUseBytes(void) const { return useBytesM; } const char *GetConfigDirectory(void) const { return configDirectoryM; } @@ -45,6 +55,7 @@ public: int GetDisabledFilters(unsigned int indexP) const; void SetOperatingMode(unsigned int operatingModeP) { operatingModeM = operatingModeP; } + void SetLogLevel(unsigned int logLevelP) { logLevelM = (logLevelP & eLogLevelMask); } void SetEITScan(unsigned int onOffP) { eitScanM = onOffP; } void SetUseBytes(unsigned int onOffP) { useBytesM = onOffP; } void SetConfigDirectory(const char *directoryP); diff --git a/discover.c b/discover.c index c4c5293..fa4aa85 100644 --- a/discover.c +++ b/discover.c @@ -196,12 +196,14 @@ void cSatipDiscover::Fetch(const char *urlP) if (handleM && !isempty(urlP)) { long rc = 0; CURLcode res = CURLE_OK; -#ifdef DEBUG + // Verbose output - SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L); - SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipDiscover::DebugCallback); - SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this); -#endif + if (SatipConfig.IsLogLevelExtra()) { + SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L); + SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipDiscover::DebugCallback); + SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this); + } + // Set callback SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEFUNCTION, cSatipDiscover::WriteCallback); SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_WRITEDATA, this); diff --git a/msearch.c b/msearch.c index 4ebfa15..047d52c 100644 --- a/msearch.c +++ b/msearch.c @@ -5,6 +5,7 @@ * */ +#include "config.h" #include "common.h" #include "discover.h" #include "poller.h" diff --git a/poller.c b/poller.c index 86036b1..c078b1c 100644 --- a/poller.c +++ b/poller.c @@ -7,6 +7,7 @@ #include +#include "config.h" #include "common.h" #include "poller.h" diff --git a/rtcp.c b/rtcp.c index 2a636ad..6105c87 100644 --- a/rtcp.c +++ b/rtcp.c @@ -5,6 +5,7 @@ * */ +#include "config.h" #include "common.h" #include "rtcp.h" diff --git a/rtp.c b/rtp.c index 43e0b45..b628ec9 100644 --- a/rtp.c +++ b/rtp.c @@ -5,6 +5,7 @@ * */ +#include "config.h" #include "common.h" #include "rtp.h" diff --git a/rtsp.c b/rtsp.c index 98eb221..a3742fd 100644 --- a/rtsp.c +++ b/rtsp.c @@ -5,6 +5,7 @@ * */ +#include "config.h" #include "common.h" #include "rtsp.h" @@ -18,12 +19,12 @@ cSatipRtsp::cSatipRtsp(cSatipTunerIf &tunerP) if (handleM) { CURLcode res = CURLE_OK; -#ifdef DEBUG // Verbose output - SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L); - SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipRtsp::DebugCallback); - SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this); -#endif + if (SatipConfig.IsLogLevelExtra()) { + SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L); + SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipRtsp::DebugCallback); + SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this); + } // No progress meter and no signaling SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_NOPROGRESS, 1L); diff --git a/satip.c b/satip.c index 94b2c9d..3ab063f 100644 --- a/satip.c +++ b/satip.c @@ -89,17 +89,21 @@ bool cPluginSatip::ProcessArgs(int argc, char *argv[]) debug("cPluginSatip::%s()", __FUNCTION__); // Implement command line argument processing here if applicable. static const struct option long_options[] = { - { "devices", required_argument, NULL, 'd' }, - { "server", required_argument, NULL, 's' }, - { NULL, no_argument, NULL, 0 } + { "devices", required_argument, NULL, 'd' }, + { "loglevel", required_argument, NULL, 'l' }, + { "server", required_argument, NULL, 's' }, + { NULL, no_argument, NULL, 0 } }; int c; - while ((c = getopt_long(argc, argv, "d:s:", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "d:l:s:", long_options, NULL)) != -1) { switch (c) { case 'd': deviceCountM = atoi(optarg); break; + case 'l': + SatipConfig.SetLogLevel(atoi(optarg)); + break; case 's': ParseServer(optarg); break; @@ -316,6 +320,8 @@ const char **cPluginSatip::SVDRPHelpPages(void) " Shows SAT>IP device count.\n", "OPER\n" " Toggles operating mode of SAT>IP devices.\n", + "LOGL [ ]\n" + " Gets and sets used logging level.\n", NULL }; return HelpPages; @@ -396,6 +402,11 @@ cString cPluginSatip::SVDRPCommand(const char *commandP, const char *optionP, in } return cString::sprintf("SAT>IP operating mode: %s\n", *mode); } + else if (strcasecmp(commandP, "LOGL") == 0) { + if (optionP && *optionP) + SatipConfig.SetLogLevel(atoi(optionP)); + return cString::sprintf("SAT>IP logging level: %d\n", SatipConfig.GetLogLevel()); + } return NULL; } diff --git a/server.c b/server.c index fb49a2b..8f60213 100644 --- a/server.c +++ b/server.c @@ -7,6 +7,7 @@ #include +#include "config.h" #include "common.h" #include "server.h"