Add a trace ID to objects.

Add debugging methods variants that print the trace ID.



git-svn-id: http://voip.null.ro/svn/yate@6402 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2020-04-22 12:00:37 +00:00
parent 47908cf938
commit 326e4941d7
3 changed files with 350 additions and 0 deletions

View File

@ -2102,6 +2102,11 @@ const String& GenObject::toString() const
return String::empty();
}
const String& GenObject::traceId() const
{
return String::empty();
}
unsigned int String::encodeFlags(const TokenDict* tokens) const
{
unsigned int flags = 0;

View File

@ -431,6 +431,182 @@ void Alarm(const DebugEnabler* component, const char* info, int level, const cha
abort();
}
void TraceDebug(const char* traceId, int level, const char* format, ...)
{
if (!s_debugging)
return;
if (level > s_debug || level < DebugMin)
return;
if (reentered())
return;
if (!format)
format = "";
char buf[OUT_HEADER_SIZE];
if (traceId)
::snprintf(buf,sizeof(buf),"<%s> Trace:%s ",dbg_level(level),traceId);
else
::sprintf(buf,"<%s> ",dbg_level(level));
va_list va;
va_start(va,format);
ind_mux.lock();
dbg_output(level,buf,format,va);
ind_mux.unlock();
va_end(va);
if (s_abort && (level == DebugFail))
abort();
}
void TraceDebug(const char* traceId, const char* facility, int level, const char* format, ...)
{
if (!s_debugging)
return;
if (level > s_debug || level < DebugMin)
return;
if (reentered())
return;
if (!format)
format = "";
char buf[OUT_HEADER_SIZE];
if (traceId)
::snprintf(buf,sizeof(buf),"<%s:%s> Trace:%s ",facility,dbg_level(level),traceId);
else
::snprintf(buf,sizeof(buf),"<%s:%s> ",facility,dbg_level(level));
va_list va;
va_start(va,format);
ind_mux.lock();
dbg_output(level,buf,format,va);
ind_mux.unlock();
va_end(va);
if (s_abort && (level == DebugFail))
abort();
}
void TraceDebug(const char* traceId, const DebugEnabler* local, int level, const char* format, ...)
{
if (!s_debugging)
return;
const char* facility = 0;
if (!local) {
if (level > s_debug || level < DebugMin)
return;
}
else {
if (!local->debugAt(level))
return;
facility = local->debugName();
}
if (reentered())
return;
if (!format)
format = "";
char buf[OUT_HEADER_SIZE];
if (facility) {
if (traceId)
::snprintf(buf,sizeof(buf),"<%s:%s> Trace:%s ",facility,dbg_level(level),traceId);
else
::snprintf(buf,sizeof(buf),"<%s:%s> ",facility,dbg_level(level));
}
else {
if (traceId)
::snprintf(buf,sizeof(buf),"<%s> Trace:%s ",dbg_level(level),traceId);
else
::sprintf(buf,"<%s> ",dbg_level(level));
}
va_list va;
va_start(va,format);
ind_mux.lock();
dbg_output(level,buf,format,va);
ind_mux.unlock();
va_end(va);
if (s_abort && (level == DebugFail))
abort();
}
void TraceAlarm(const char* traceId, const char* component, int level, const char* format, ...)
{
if (!format || level < DebugMin || reentered())
return;
if (TelEngine::null(component))
component = "unknown";
char buf[OUT_HEADER_SIZE];
if (traceId)
::snprintf(buf,sizeof(buf),"<%s:%s> Trace:%s ",component,dbg_level(level),traceId);
else
::snprintf(buf,sizeof(buf),"<%s:%s> ",component,dbg_level(level));
va_list va;
va_start(va,format);
ind_mux.lock();
dbg_output(level,buf,format,va,component);
ind_mux.unlock();
va_end(va);
if (s_abort && (level == DebugFail))
abort();
}
void TraceAlarm(const char* traceId, const DebugEnabler* component, int level, const char* format, ...)
{
if (!format || level < DebugMin || reentered())
return;
const char* name = (component && !TelEngine::null(component->debugName()))
? component->debugName() : "unknown";
char buf[OUT_HEADER_SIZE];
if (traceId)
::snprintf(buf,sizeof(buf),"<%s:%s> Trace:%s ",name,dbg_level(level),traceId);
else
::snprintf(buf,sizeof(buf),"<%s:%s> ",name,dbg_level(level));
va_list va;
va_start(va,format);
ind_mux.lock();
dbg_output(level,buf,format,va,name);
ind_mux.unlock();
va_end(va);
if (s_abort && (level == DebugFail))
abort();
}
void TraceAlarm(const char* traceId, const char* component, const char* info, int level, const char* format, ...)
{
if (!format || level < DebugMin || reentered())
return;
if (TelEngine::null(component))
component = "unknown";
char buf[OUT_HEADER_SIZE];
if (traceId)
::snprintf(buf,sizeof(buf),"<%s:%s> Trace:%s ",component,dbg_level(level),traceId);
else
::snprintf(buf,sizeof(buf),"<%s:%s> ",component,dbg_level(level));
va_list va;
va_start(va,format);
ind_mux.lock();
dbg_output(level,buf,format,va,component,info);
ind_mux.unlock();
va_end(va);
if (s_abort && (level == DebugFail))
abort();
}
void TraceAlarm(const char* traceId, const DebugEnabler* component, const char* info, int level, const char* format, ...)
{
if (!format || level < DebugMin || reentered())
return;
const char* name = (component && !TelEngine::null(component->debugName()))
? component->debugName() : "unknown";
char buf[OUT_HEADER_SIZE];
if (traceId)
::snprintf(buf,sizeof(buf),"<%s:%s> Trace:%s ",name,dbg_level(level),traceId);
else
::snprintf(buf,sizeof(buf),"<%s:%s> ",name,dbg_level(level));
va_list va;
va_start(va,format);
ind_mux.lock();
dbg_output(level,buf,format,va,name,info);
ind_mux.unlock();
va_end(va);
if (s_abort && (level == DebugFail))
abort();
}
void abortOnBug()
{
if (s_abort)

View File

@ -561,6 +561,169 @@ YATE_API void Alarm(const DebugEnabler* component, const char* info, int level,
*/
YATE_API void Output(const char* format, ...) FORMAT_CHECK(1);
/**
* Outputs a debug string with a trace ID.
* @param traceId The trace ID associated with this message
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void TraceDebug(const char* traceId, int level, const char* format, ...) FORMAT_CHECK(3);
/**
* Outputs a debug string with a trace ID.
* @param traceId The trace ID associated with this message
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void TraceDebug(const char* traceId, const char* facility, int level,
const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a debug string with a trace ID.
* @param traceId The trace ID associated with this message
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
YATE_API void TraceDebug(const char* traceId, const DebugEnabler* local, int level,
const char* format, ...) FORMAT_CHECK(4);
#if 0 /* for documentation generator */
/**
* Outputs a debug string with a trace ID.
* @param obj Object from where to get trace ID
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceDebugObj(GenObject* obj, int level, const char* format, ...);
/**
* Outputs a debug string with a trace ID.
* @param obj Object from where to get trace ID
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceDebugObj(GenObject* obj, const char* facility, int level, const char* format, ...);
/**
* Outputs a debug string with a trace ID.
* @param obj Object from where to get trace ID
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceDebugObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param level The level of the message
* @param format A printf() style format string
*/
void Trace(GenObject* obj, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
void Trace(GenObject* obj, const char* facility, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
void Trace(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceObj(GenObject* obj, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param facility Facility that outputs the message
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceObj(GenObject* obj, const char* facility, int level, const char* format, ...);
/**
* Outputs a debug string only if trace ID is valid.
* @param obj Object from where to get trace ID
* @param local Pointer to a DebugEnabler holding current debugging settings
* @param level The level of the message
* @param format A printf() style format string
*/
void TraceObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
#endif
#define TraceDebugObj(pGenObj,...) \
TraceDebug((!!(pGenObj)) ? (pGenObj)->traceId() : "",##__VA_ARGS__)
#define Trace(traceId,...) \
do { if (!TelEngine::null(traceId)) TraceDebug(traceId,##__VA_ARGS__); } while(false)
#define TraceObj(pGenObj,...) \
do { if (!!(pGenObj) && (pGenObj)->traceId()) TraceDebug((pGenObj)->traceId(),##__VA_ARGS__); } while (false)
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Component that emits the alarm
* @param info Extra alarm information
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const char* component, int level,
const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Pointer to a DebugEnabler holding component name and debugging settings
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
int level, const char* format, ...) FORMAT_CHECK(4);
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Component that emits the alarm
* @param info Extra alarm information
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const char* component, const char* info,
int level, const char* format, ...) FORMAT_CHECK(5);
/**
* Outputs a debug string with trace ID and emits an alarm if a callback is installed
* @param traceId The trace ID associated with this message
* @param component Pointer to a DebugEnabler holding component name and debugging settings
* @param info Extra alarm information
* @param level The level of the alarm
* @param format A printf() style format string
*/
YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
const char* info, int level, const char* format, ...) FORMAT_CHECK(5);
/**
* This class is used as an automatic variable that logs messages on creation
* and destruction (when the instruction block is left or function returns).
@ -880,6 +1043,12 @@ public:
*/
virtual const String& toString() const;
/**
* Get the trace ID associated with this object
* @return The trace ID or an empty string
*/
virtual const String& traceId() const;
/**
* Get a pointer to a derived class given that class name
* @param name Name of the class we are asking for