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
This commit is contained in:
marian 2022-12-13 06:57:11 +00:00
parent f7df31d03d
commit 39815923a3
4 changed files with 52 additions and 30 deletions

View File

@ -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);

View File

@ -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<NamedString*>(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<Plugin *>(l->get());
TempObjectCounter cnt(p->objectsCounter(),true);
if (s_debug)
p->debugSet(s_debugInit[p->toString()]);
p->initialize();
if (exiting()) {
Output("Initialization aborted, exiting...");

View File

@ -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)
{

View File

@ -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