modify sofia debug code to print file, line numbers and function name

This commit is contained in:
Anthony Minessale committed 2012-10-26 14:15:14 -05:00
1 parent 28aa2ad291
commit 63e2044a7e
17 files changed
+96 -62

No files matched your search

@@ -73,13 +73,17 @@ SOFIA_BEGIN_DECLS
SOFIAPUBVAR su_log_t SU_LOG[];
#endif
#define VA_NONE "%s",""
#define SU_DEBUG_DEF(level) \
su_inline void su_debug_##level(char const *fmt, ...) \
__attribute__ ((__format__ (printf, 1, 2))); \
su_inline void su_debug_##level(char const *fmt, ...) \
{ va_list ap; va_start(ap, fmt); su_vllog(SU_LOG, level, fmt, ap); va_end(ap); }
{ va_list ap; va_start(ap, fmt); su_vllog(SU_LOG, level, fmt, ap); va_end(ap); }
//SU_DEBUG_DEF(0)
#define su_debug_0(_f, ...) su_llog(SU_LOG, 0, _f, __VA_ARGS__)
SU_DEBUG_DEF(0)
/** Log messages at level 0.
*
* Fatal errors and panic messages should be logged at level 0.
@@ -100,7 +104,10 @@ SU_DEBUG_DEF(0)
#endif
#if SU_DEBUG_MAX >= 1
SU_DEBUG_DEF(1)
//SU_DEBUG_DEF(1)
#define su_debug_1(_f, ...) su_llog(SU_LOG, 1, _f, __VA_ARGS__)
/**Log messages at level 1.
*
* Critical errors and minimal progress at subsystem level should be logged
@@ -114,7 +121,8 @@ SU_DEBUG_DEF(1)
#endif
#if SU_DEBUG_MAX >= 2
SU_DEBUG_DEF(2)
//SU_DEBUG_DEF(2)
#define su_debug_2(_f, ...) su_llog(SU_LOG, 2, _f, __VA_ARGS__)
/**Log messages at level 2.
*
* Non-critical errors should be logged at level 2.
@@ -127,7 +135,8 @@ SU_DEBUG_DEF(2)
#endif
#if SU_DEBUG_MAX >= 3
SU_DEBUG_DEF(3)
//SU_DEBUG_DEF(3)
#define su_debug_3(_f, ...) su_llog(SU_LOG, 3, _f, __VA_ARGS__)
/** Log messages at level 3.
*
* Warnings and progress messages should be logged at level 3.
@@ -140,7 +149,8 @@ SU_DEBUG_DEF(3)
#endif
#if SU_DEBUG_MAX >= 4
SU_DEBUG_DEF(4)
//SU_DEBUG_DEF(4)
#define su_debug_4(_f, ...) su_llog(SU_LOG, 4, _f, __VA_ARGS__)
/** Log messages at level 4. */
#define SU_DEBUG_4(x) (SU_LOG_LEVEL >= 4 ? (su_debug_4 x) : (void)0)
#else
@@ -148,7 +158,8 @@ SU_DEBUG_DEF(4)
#endif
#if SU_DEBUG_MAX >= 5
SU_DEBUG_DEF(5)
//SU_DEBUG_DEF(5)
#define su_debug_5(_f, ...) su_llog(SU_LOG, 5, _f, __VA_ARGS__)
/** Log messages at level 5.
*
* Signaling protocol actions (incoming packets, etc.) should be logged
@@ -162,7 +173,8 @@ SU_DEBUG_DEF(5)
#endif
#if SU_DEBUG_MAX >= 6
SU_DEBUG_DEF(6)
//SU_DEBUG_DEF(6)
#define su_debug_6(_f, ...) su_llog(SU_LOG, 6, _f, __VA_ARGS__)
/** Log messages at level 6. */
#define SU_DEBUG_6(x) (SU_LOG_LEVEL >= 6 ? (su_debug_6 x) : (void)0)
#else
@@ -170,7 +182,8 @@ SU_DEBUG_DEF(6)
#endif
#if SU_DEBUG_MAX >= 7
SU_DEBUG_DEF(7)
//SU_DEBUG_DEF(7)
#define su_debug_7(_f, ...) su_llog(SU_LOG, 7, _f, __VA_ARGS__)
/** Log messages at level 7.
*
* Media protocol actions (incoming packets, etc) should be logged at level 7.
@@ -183,7 +196,8 @@ SU_DEBUG_DEF(7)
#endif
#if SU_DEBUG_MAX >= 8
SU_DEBUG_DEF(8)
//SU_DEBUG_DEF(8)
#define su_debug_8(_f, ...) su_llog(SU_LOG, 8, _f, __VA_ARGS__)
/** Log messages at level 8. */
#define SU_DEBUG_8(x) (SU_LOG_LEVEL >= 8 ? (su_debug_8 x) : (void)0)
#else
@@ -191,7 +205,8 @@ SU_DEBUG_DEF(8)
#endif
#if SU_DEBUG_MAX >= 9
SU_DEBUG_DEF(9)
//SU_DEBUG_DEF(9)
#define su_debug_9(_f, ...) su_llog(SU_LOG, 9, _f, __VA_ARGS__)
/** Log messages at level 9.
*
* Entering/exiting functions, very verbatim progress should be logged at
@@ -52,6 +52,15 @@ typedef struct su_log_s su_log_t;
SOFIA_BEGIN_DECLS
#ifdef _MSC_VER
#define __SOFIA_FUNC__ __FUNCTION__
#else
#define __SOFIA_FUNC__ (const char *)__func__
#endif
/** Prototype for logging function */
typedef void (su_logger_f)(void *stream, char const *fmt, va_list ap);
@@ -77,9 +86,9 @@ enum { SU_LOG_MAX = 9 };
SOFIAPUBFUN void su_log(char const *fmt, ...)
__attribute__ ((__format__ (printf, 1, 2)));
SOFIAPUBFUN void su_llog(su_log_t *log, unsigned level, char const *fmt, ...)
__attribute__ ((__format__ (printf, 3, 4)));
SOFIAPUBFUN void su_vllog(su_log_t *log, unsigned level,
SOFIAPUBFUN void _su_llog(su_log_t *log, unsigned level, const char *file, const char *func, int line, char const *fmt, ...)
__attribute__ ((__format__ (printf, 6, 7)));
SOFIAPUBFUN void _su_vllog(su_log_t *log, unsigned level, const char *file, const char *func, int line,
char const *fmt, va_list ap);
SOFIAPUBFUN void su_log_redirect(su_log_t *log, su_logger_f *f, void *stream);
SOFIAPUBFUN void su_log_set_level(su_log_t *log, unsigned level);
@@ -92,6 +101,9 @@ SOFIAPUBVAR su_log_t su_log_global[];
/** Log the latest su error message */
SOFIAPUBFUN void su_perror(char const *s);
#define su_llog(_l, _ll, _f, ...) _su_llog(_l, _ll, __FILE__, __SOFIA_FUNC__, __LINE__, _f, __VA_ARGS__)
#define su_vllog(_l, _ll, _f, ...) _su_vllog(_l, _ll, __FILE__, __SOFIA_FUNC__, __LINE__, _f, __VA_ARGS__)
/** Log the su error message. */
SOFIAPUBFUN void su_perror2(char const *s, int errcode);
@@ -1260,7 +1260,7 @@ int bsd_localinfo(su_localinfo_t const hints[1],
flags |= LI_NUMERIC;
if (!(li = calloc(1, sizeof(*li) + sulen + ifnamelen))) {
SU_DEBUG_1(("su_getlocalinfo: memory exhausted\n"));
SU_DEBUG_1(("su_getlocalinfo: memory exhausted\n" VA_NONE));
error = ELI_MEMORY;
break;
}
@@ -1629,7 +1629,7 @@ int li_name(su_localinfo_t const *hints,
if (error) {
if ((flags & LI_NAMEREQD) == LI_NAMEREQD)
return 1;
SU_DEBUG_7(("li_name: getnameinfo() failed\n"));
SU_DEBUG_7(("li_name: getnameinfo() failed\n" VA_NONE));
if (!su_inet_ntop(su->su_family, SU_ADDR(su), name, sizeof name))
return ELI_RESOLVER;
}
+13 -6
View File
@@ -100,17 +100,23 @@ void su_log(char const *fmt, ...)
*
* @note This function is used mainly by SU_DEBUG_n() macros.
*/
void su_llog(su_log_t *log, unsigned level, char const *fmt, ...)
void _su_llog(su_log_t *log, unsigned level, const char *file, const char *func, int line,
char const *fmt, ...)
{
va_list ap;
char buf[512];
va_start(ap, fmt);
su_vllog(log, level, fmt, ap);
snprintf(buf, sizeof(buf), "%s:%d %s() %s", file, line, func, fmt);
_su_vllog(log, level, file, func, line, buf, ap);
va_end(ap);
}
/** Log a message with level (stdarg version). */
void su_vllog(su_log_t *log, unsigned level, char const *fmt, va_list ap)
void _su_vllog(su_log_t *log, unsigned level, const char *file, const char *func, int line,
char const *fmt, va_list ap)
{
su_logger_f *logger;
void *stream;
@@ -133,8 +139,9 @@ void su_vllog(su_log_t *log, unsigned level, char const *fmt, va_list ap)
stream = su_log_default->log_stream;
}
if (logger)
logger(stream, fmt, ap);
if (logger) {
logger(stream, fmt, ap);
}
}
static char const not_initialized[1];