Added extmodule support to put a script requested debug message in yate output/logging. Added support to change script's debug level and debug name.

git-svn-id: http://yate.null.ro/svn/yate/trunk@6472 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2021-04-01 09:10:07 +00:00
parent b482039d8a
commit d81d1f7452
2 changed files with 41 additions and 2 deletions

View File

@ -212,6 +212,8 @@ setdata (bool) - Attach channel pointer as user data to generated messages<br />
reenter (bool) - If this module is allowed to handle messages generated by itself<br /> reenter (bool) - If this module is allowed to handle messages generated by itself<br />
selfwatch (bool) - If this module is allowed to watch messages generated by itself<br /> selfwatch (bool) - If this module is allowed to watch messages generated by itself<br />
restart (bool) - Restart this global module if it terminates unexpectedly. Must be turned off to allow normal termination<br /> restart (bool) - Restart this global module if it terminates unexpectedly. Must be turned off to allow normal termination<br />
debuglevel (int) - Set module debug level<br />
debugname (string) - Set module's debug name. One time only set is allowed, subsequent requests will be ignored<br />
<b>Engine read-only run parameters:</b><br /> <b>Engine read-only run parameters:</b><br />
engine.version (string,readonly) - Version of the engine, like &quot;2.0.1&quot;<br /> engine.version (string,readonly) - Version of the engine, like &quot;2.0.1&quot;<br />
engine.release (string,readonly) - Release type and number, like &quot;beta2&quot;<br /> engine.release (string,readonly) - Release type and number, like &quot;beta2&quot;<br />
@ -252,6 +254,15 @@ This is the proper way of logging messages for programs that connect to the
socket interface as they may not have the standard error redirected.<br /> socket interface as they may not have the standard error redirected.<br />
</p> </p>
<p><b>Keyword: %%&gt;debug</b><br />
%%&gt;debug:&lt;level&gt;:arbitrary escaped string<br />
<b>Direction: Application to engine</b><br />
The &quot;debug&quot; keyword is used to print arbitrary messages to
engine's logging output using specified debug level.<br />
This is the proper way of logging messages for programs that connect to the
socket interface as they may not have the standard error redirected.<br />
</p>
<p><b>Keyword: %%&gt;connect</b><br /> <p><b>Keyword: %%&gt;connect</b><br />
%%&gt;connect:&lt;role&gt;[:&lt;id&gt;][:&lt;type&gt;]<br /> %%&gt;connect:&lt;role&gt;[:&lt;id&gt;][:&lt;type&gt;]<br />
<b>Direction: Application to engine</b><br /> <b>Direction: Application to engine</b><br />

View File

@ -213,7 +213,7 @@ private:
ObjList m_watched; ObjList m_watched;
}; };
class ExtModReceiver : public MessageReceiver, public Mutex class ExtModReceiver : public MessageReceiver, public Mutex, public DebugEnabler
{ {
friend class MsgWatcher; friend class MsgWatcher;
public: public:
@ -293,6 +293,7 @@ private:
ObjList m_relays; ObjList m_relays;
String m_trackName; String m_trackName;
String m_reason; String m_reason;
String m_debugName;
}; };
class ExtThread : public Thread class ExtThread : public Thread
@ -803,6 +804,8 @@ ExtModReceiver::ExtModReceiver(const char* script, const char* args, File* ain,
m_maxQueue(s_maxQueue), m_timeout(s_timeout), m_timebomb(s_timebomb), m_restart(false), m_scripted(false), m_maxQueue(s_maxQueue), m_timeout(s_timeout), m_timebomb(s_timebomb), m_restart(false), m_scripted(false),
m_buffer(0,DEF_INCOMING_LINE), m_script(script), m_args(args), m_trackName(s_trackName) m_buffer(0,DEF_INCOMING_LINE), m_script(script), m_args(args), m_trackName(s_trackName)
{ {
debugChain(&__plugin);
debugName(m_script);
Debug(DebugAll,"ExtModReceiver::ExtModReceiver(\"%s\",\"%s\") [%p]",script,args,this); Debug(DebugAll,"ExtModReceiver::ExtModReceiver(\"%s\",\"%s\") [%p]",script,args,this);
m_script.trimBlanks(); m_script.trimBlanks();
m_args.trimBlanks(); m_args.trimBlanks();
@ -821,6 +824,8 @@ ExtModReceiver::ExtModReceiver(const char* name, Stream* io, ExtModChan* chan, i
m_maxQueue(s_maxQueue), m_timeout(s_timeout), m_timebomb(s_timebomb), m_restart(false), m_scripted(false), m_maxQueue(s_maxQueue), m_timeout(s_timeout), m_timebomb(s_timebomb), m_restart(false), m_scripted(false),
m_buffer(0,DEF_INCOMING_LINE), m_script(name), m_args(conn), m_trackName(s_trackName) m_buffer(0,DEF_INCOMING_LINE), m_script(name), m_args(conn), m_trackName(s_trackName)
{ {
debugChain(&__plugin);
debugName(m_script);
Debug(DebugAll,"ExtModReceiver::ExtModReceiver(\"%s\",%p,%p) [%p]",name,io,chan,this); Debug(DebugAll,"ExtModReceiver::ExtModReceiver(\"%s\",%p,%p) [%p]",name,io,chan,this);
m_script.trimBlanks(); m_script.trimBlanks();
m_args.trimBlanks(); m_args.trimBlanks();
@ -1224,7 +1229,7 @@ void ExtModReceiver::run()
Debug("ExtModule",DebugWarn,"Read error %d on %p [%p]",errno,m_in,this); Debug("ExtModule",DebugWarn,"Read error %d on %p [%p]",errno,m_in,this);
break; break;
} }
XDebug(DebugAll,"ExtModReceiver::run() read %d",readsize); XDebug(DebugAll,"ExtModReceiver::run() read %d [%p]",readsize,this);
int totalsize = readsize + posinbuf; int totalsize = readsize + posinbuf;
if (totalsize >= (int)m_buffer.length()) { if (totalsize >= (int)m_buffer.length()) {
Debug("ExtModule",DebugWarn,"Overflow reading in buffer of length %u, closing [%p]", Debug("ExtModule",DebugWarn,"Overflow reading in buffer of length %u, closing [%p]",
@ -1504,6 +1509,14 @@ bool ExtModReceiver::processLine(const char* line)
Output("%s",id.safe()); Output("%s",id.safe());
return false; return false;
} }
else if (id.startSkip("%%>debug:",false)) {
int pos = id.find(':');
if (pos > 0) {
int level = id.substr(0,pos).toInteger(DebugAll,0,DebugTest,DebugAll);
Debug(this,level,"%s",String::msgUnescape(id.substr(pos + 1)).safe());
return false;
}
}
else if (id.startSkip("%%>setlocal:",false)) { else if (id.startSkip("%%>setlocal:",false)) {
int col = id.find(':'); int col = id.find(':');
if (col > 0) { if (col > 0) {
@ -1622,6 +1635,21 @@ bool ExtModReceiver::processLine(const char* line)
ok = val.null(); ok = val.null();
val = Engine::runId(); val = Engine::runId();
} }
else if (id == YSTRING("debuglevel")) {
ok = true;
if (val)
debugLevel(val.toInteger(DebugAll,0,DebugTest,DebugAll));
val = debugLevel();
}
else if (id == YSTRING("debugname")) {
ok = true;
if (val && !m_debugName) {
m_debugName = val;
debugName(m_debugName);
}
else
val = debugName();
}
DDebug("ExtModReceiver",DebugAll,"Set '%s'='%s' %s", DDebug("ExtModReceiver",DebugAll,"Set '%s'='%s' %s",
id.c_str(),val.c_str(),ok ? "ok" : "failed"); id.c_str(),val.c_str(),ok ? "ok" : "failed");
String out("%%<setlocal:"); String out("%%<setlocal:");