From 39815923a3f25c087c719dbc9c8d088b1911ed91 Mon Sep 17 00:00:00 2001 From: marian Date: Tue, 13 Dec 2022 06:57:11 +0000 Subject: [PATCH] Apply module debug from main config file when initializing plugins at startup. This allows a module to show debug messages on first init. git-svn-id: http://voip.null.ro/svn/yate@6574 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/Channel.cpp | 25 +++++++------------------ engine/Engine.cpp | 26 ++++++++++++++------------ engine/TelEngine.cpp | 25 +++++++++++++++++++++++++ yateclass.h | 6 ++++++ 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/engine/Channel.cpp b/engine/Channel.cpp index 61df7127..743c5a78 100644 --- a/engine/Channel.cpp +++ b/engine/Channel.cpp @@ -1333,28 +1333,17 @@ bool Module::setDebug(Message& msg, const String& target) return false; NamedCounter* counter = objectsCounter(); - String str = msg.getValue("line"); - if (str.startSkip("level")) { - int dbg = debugLevel(); - str >> dbg; - if (str == "+") { - if (debugLevel() > dbg) - dbg = debugLevel(); - } - else if (str == "-") { - if (debugLevel() < dbg) - dbg = debugLevel(); - } - debugLevel(dbg); - } - else if (str == "reset") { - debugLevel(TelEngine::debugLevel()); - debugEnabled(true); + const String& line = msg[YSTRING("line")]; + debugSet(line); + String str = line; + if (str.startSkip("level")) + ; + else if (str == YSTRING("reset")) { if (counter) counter->enable(getObjCounting()); } else if (str.startSkip("objects")) { - bool dbg = (str == "reset") ? getObjCounting() : (counter && counter->enabled()); + bool dbg = (str == YSTRING("reset")) ? getObjCounting() : (counter && counter->enabled()); str >> dbg; if (counter) counter->enable(dbg); diff --git a/engine/Engine.cpp b/engine/Engine.cpp index 4a31d47c..0f9c0b52 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -305,6 +305,7 @@ static int s_exit = -1; unsigned int Engine::s_congestion = 0; static Mutex s_congMutex(false,"Congestion"); static bool s_debug = true; +static NamedList s_debugInit(""); static bool s_capture = CAPTURE_EVENTS; static int s_maxevents = 25; static Mutex s_eventsMutex(false,"EventsList"); @@ -1584,6 +1585,9 @@ int Engine::engineInit() CapturedEvent::capturing(s_capture); s_cfg = configFile(s_cfgfile); s_cfg.load(); + NamedList* sect = s_cfg.getSection(YSTRING("debug")); + if (sect) + s_debugInit.copyParams(false,*sect); s_capture = s_cfg.getBoolValue("general","startevents",s_capture); CapturedEvent::capturing(s_capture); if (s_capture && s_startMsg) @@ -1859,18 +1863,14 @@ int Engine::run() if (s_debug) { // one-time sending of debug setup messages s_debug = false; - const NamedList* sect = s_cfg.getSection("debug"); - if (sect) { - unsigned int n = sect->length(); - for (unsigned int i = 0; i < n; i++) { - const NamedString* str = sect->getParam(i); - if (!(str && str->name() && *str)) - continue; - Message* m = new Message("engine.debug"); - m->addParam("module",str->name()); - m->addParam("line",*str); - enqueue(m); - } + for (ObjList* o = s_debugInit.paramList()->skipNull(); o; o = o->skipNext()) { + const NamedString* str = static_cast(o->get()); + if (!(str->name() && *str)) + continue; + Message* m = new Message("engine.debug"); + m->addParam("module",str->name()); + m->addParam("line",*str); + enqueue(m); } } else if (s_capture) { @@ -2278,6 +2278,8 @@ void Engine::initPlugins() for (; l; l = l->skipNext()) { Plugin *p = static_cast(l->get()); TempObjectCounter cnt(p->objectsCounter(),true); + if (s_debug) + p->debugSet(s_debugInit[p->toString()]); p->initialize(); if (exiting()) { Output("Initialization aborted, exiting..."); diff --git a/engine/TelEngine.cpp b/engine/TelEngine.cpp index 3b4d79f1..5be9020b 100644 --- a/engine/TelEngine.cpp +++ b/engine/TelEngine.cpp @@ -684,6 +684,31 @@ void DebugEnabler::debugCopy(const DebugEnabler* original) m_chain = 0; } +void DebugEnabler::debugSet(const char* desc) +{ + if (TelEngine::null(desc)) + return; + String s(desc); + if (s.startSkip("level")) { + int dbg = debugLevel(); + s >> dbg; + if (s == YSTRING("+")) { + if (debugLevel() > dbg) + dbg = debugLevel(); + } + else if (s == YSTRING("-")) { + if (debugLevel() < dbg) + dbg = debugLevel(); + } + debugLevel(dbg); + } + else if (s == YSTRING("reset")) { + debugLevel(TelEngine::debugLevel()); + debugEnabled(true); + } +} + + Debugger::Debugger(const char* name, const char* format, ...) : m_name(name), m_level(DebugAll) { diff --git a/yateclass.h b/yateclass.h index d128cf5a..0d1a9a87 100644 --- a/yateclass.h +++ b/yateclass.h @@ -385,6 +385,12 @@ public: */ void debugCopy(const DebugEnabler* original = 0); + /** + * Set debug from description + * @param desc Debug description. [level [NNN][+-]] or 'reset' + */ + void debugSet(const char* desc); + protected: /** * Set the current debug name