Changeset 965:9b37f34c1b1f in freeDiameter for include/freeDiameter/libfdproto.h
- Timestamp:
- Mar 13, 2013, 1:23:37 AM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/libfdproto.h
r961 r965 112 112 * FUNCTION: fd_log 113 113 * MACRO: fd_log_debug 114 * MACRO: fd_log_notice 115 * MACRO: fd_log_error 114 116 * 115 117 * PARAMETERS: … … 127 129 */ 128 130 void fd_log ( int, const char *, ... ); 129 #define fd_log_debug(format,args...) fd_log(FD_LOG_DEBUG, format, ## args) 131 #define fd_log_debug(format,args...) fd_log(FD_LOG_DEBUG, format, ## args) 132 #define fd_log_notice(format,args...) fd_log(FD_LOG_NOTICE, format, ## args) 133 #define fd_log_error(format,args...) fd_log(FD_LOG_ERROR, format, ## args) 134 130 135 void fd_log_debug_fstr( FILE *, const char *, ... ); 131 136 … … 211 216 212 217 /* log levels definitions */ 213 #define FD_LOG_DEBUG 0 214 #define FD_LOG_ERROR 5 218 #define FD_LOG_DEBUG 0 /* Verbose information for developers use */ 219 #define FD_LOG_NOTICE 3 /* Normal execution states worth noting */ 220 #define FD_LOG_ERROR 5 /* Error conditions, both recoverable or not */ 215 221 216 222 /* print level definitions */ … … 252 258 253 259 254 #define STD_TRACE_FMT_STRING " thread%s in %s@%s:%d: "260 #define STD_TRACE_FMT_STRING "pid:%s in %s@%s:%d: " 255 261 /************* 256 262 The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) … … 258 264 #ifdef DEBUG 259 265 /* In DEBUG mode, we add (a lot of) meta-information along each trace. This makes multi-threading problems easier to debug. */ 260 #define TRACE _DEBUG(level,format,args... ) {\266 #define TRACE(printlevel,level,format,args... ) { \ 261 267 if ( TRACE_BOOL(level) ) { \ 262 268 const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 263 fd_log( level, STD_TRACE_FMT_STRING format,\264 __thn, __PRETTY_FUNCTION__, __ FILE__, __LINE__, ## args);\269 fd_log((printlevel), STD_TRACE_FMT_STRING format, \ 270 __thn, __PRETTY_FUNCTION__, __STRIPPED_FILE__, __LINE__, ## args); \ 265 271 } \ 266 272 } 267 273 #else /* DEBUG */ 268 /* Do not print thread, function, ... only the message itself in this case, unless the debug level is set > FULL. */ 269 #define TRACE_DEBUG(level,format,args... ) { \ 270 if ( TRACE_BOOL(level) ) { \ 271 if (fd_g_debug_lvl > FULL) { \ 272 const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 273 fd_log(level, STD_TRACE_FMT_STRING format, \ 274 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## args); \ 275 } else { \ 276 fd_log(level, format, ## args); \ 277 } \ 278 } \ 274 /* Do not print thread, function, ... only the message itself in this case */ 275 #define TRACE(printlevel,level,format,args... ) { \ 276 if ( TRACE_BOOL(level) ) { \ 277 fd_log((printlevel), format, ## args); \ 278 } \ 279 279 } 280 280 #endif /* DEBUG */ 281 281 282 /* Report debug information */ 283 #define TRACE_DEBUG(level,format,args... ) \ 284 TRACE(FD_LOG_DEBUG,(level),format,##args) 285 286 /* Report a normal message that is usefull for normal admin monitoring */ 287 #define TRACE_NOTICE(format,args... ) \ 288 TRACE(FD_LOG_NOTICE,INFO,format,##args) 289 290 /* Report an error */ 291 #define TRACE_ERROR(format,args... ) \ 292 TRACE(FD_LOG_ERROR, NONE, format, ##args) 293 294 /* 295 TRACE_NOTICE(...) and fd_log_notice(...) are equivalent when the code is not compiled in DEBUG mode, 296 but there is more contextual information when compiled in DEBUG with the TRACE_NOTICE macro, 297 hence it is recommended to use this one except for formatted output (e.g. fd_*_dump function) 298 299 resp. TRACE_DEBUG and TRACE_ERROR. 300 */ 301 282 302 /************* 283 Derivatives f rom this macro303 Derivatives for debug 284 304 ************/ 285 305 /* Helper for function entry -- for very detailed trace of the execution */ … … 306 326 307 327 /* Trace a binary buffer content */ 308 #define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) { \ 328 #ifdef DEBUG 329 /* In DEBUG mode, we add (a lot of) meta-information along each trace. This makes multi-threading problems easier to debug. */ 330 #define TRACE_BUFFER(printlevel, level, prefix, buf, bufsz, suffix ) { \ 309 331 if ( TRACE_BOOL(level) ) { \ 310 332 int __i; \ 311 333 size_t __sz = (size_t)(bufsz); \ 312 334 uint8_t * __buf = (uint8_t *)(buf); \ 335 char __strbuf[1024+1]; \ 313 336 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 314 fd_log(level, STD_TRACE_FMT_STRING prefix, \ 315 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__); \ 316 for (__i = 0; __i < __sz; __i++) { \ 317 fd_log(level, "%02.2hhx", __buf[__i]); \ 337 for (__i = 0; (__i < __sz) && (__i<(sizeof(__strbuf)/2)); __i++) { \ 338 sprintf(__strbuf + (2 * __i), "%2.2hhx", __buf[__i]); \ 318 339 } \ 319 fd_log(level, suffix); \ 340 fd_log(printlevel, STD_TRACE_FMT_STRING "%s%s%s", \ 341 __thn, __PRETTY_FUNCTION__, __STRIPPED_FILE__, __LINE__, (prefix), __strbuf, (suffix)); \ 320 342 } \ 321 343 } 344 #else /* DEBUG */ 345 /* Do not print thread, function, ... only the message itself in this case */ 346 #define TRACE_BUFFER(printlevel, level, prefix, buf, bufsz, suffix ) { \ 347 if ( TRACE_BOOL(level) ) { \ 348 int __i; \ 349 size_t __sz = (size_t)(bufsz); \ 350 uint8_t * __buf = (uint8_t *)(buf); \ 351 char __strbuf[1024+1]; \ 352 for (__i = 0; (__i < __sz) && (__i<(sizeof(__strbuf)/2)); __i++) { \ 353 sprintf(__strbuf + (2 * __i), "%2.2hhx", __buf[__i]); \ 354 } \ 355 fd_log(printlevel, "%s%s%s", (prefix), __strbuf, (suffix)); \ 356 } \ 357 } 358 #endif /* DEBUG */ 322 359 323 360 /* Some aliases to socket addresses structures */ … … 334 371 335 372 /* Dump one sockaddr Node information */ 336 #define sSA_DUMP_NODE( buf, bufsize, sa, flag ) { \337 sSA * __sa = (sSA *)(sa); \338 char __addrbuf[INET6_ADDRSTRLEN]; \339 if (__sa) { \340 int __rc = getnameinfo(__sa, \341 sSAlen(__sa), \342 __addrbuf, \343 sizeof(__addrbuf), \344 NULL, \345 0, \346 flag); \347 if (__rc) \373 #define sSA_DUMP_NODE( buf, bufsize, sa, flag ) { \ 374 sSA * __sa = (sSA *)(sa); \ 375 char __addrbuf[INET6_ADDRSTRLEN]; \ 376 if (__sa) { \ 377 int __rc = getnameinfo(__sa, \ 378 sSAlen(__sa), \ 379 __addrbuf, \ 380 sizeof(__addrbuf), \ 381 NULL, \ 382 0, \ 383 (flag)); \ 384 if (__rc) \ 348 385 snprintf(buf, bufsize, "%s", gai_strerror(__rc)); \ 349 else \350 snprintf(buf, bufsize, "%s", &__addrbuf[0]); \351 } else { \352 snprintf(buf, bufsize, "(NULL / ANY)"); \353 } \386 else \ 387 snprintf(buf, bufsize, "%s", &__addrbuf[0]); \ 388 } else { \ 389 snprintf(buf, bufsize, "(NULL / ANY)"); \ 390 } \ 354 391 } 355 392 /* Same but with the port (service) also */ … … 365 402 __servbuf, \ 366 403 sizeof(__servbuf), \ 367 flag);\404 (flag)); \ 368 405 if (__rc) \ 369 406 snprintf(buf, bufsize, "%s", gai_strerror(__rc)); \ … … 375 412 } 376 413 377 /* Inside a debug trace */ 378 #define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) { \ 414 #ifdef DEBUG 415 /* In DEBUG mode, we add (a lot of) meta-information along each trace. This makes multi-threading problems easier to debug. */ 416 #define TRACE_sSA(printlevel, level, prefix, sa, flags, suffix ) { \ 379 417 if ( TRACE_BOOL(level) ) { \ 380 char buf[1024];\418 char __buf[1024]; \ 381 419 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 382 sSA_DUMP_NODE_SERV( buf, sizeof(buf), sa, flags );\383 fd_log( level, STD_TRACE_FMT_STRING "%s%s%s",\384 __thn, __PRETTY_FUNCTION__, __ FILE__, __LINE__, prefix, buf, suffix);\420 sSA_DUMP_NODE_SERV(__buf, sizeof(__buf), sa, flags ); \ 421 fd_log(printlevel, STD_TRACE_FMT_STRING "%s%s%s" , \ 422 __thn, __PRETTY_FUNCTION__, __STRIPPED_FILE__, __LINE__, (prefix), __buf, (suffix)); \ 385 423 } \ 386 424 } 387 388 /* Report an error */ 389 #define TRACE_DEBUG_ERROR(format,args... ) \ 390 TRACE_DEBUG(INFO, format, ##args) 425 #else /* DEBUG */ 426 /* Do not print thread, function, ... only the message itself in this case */ 427 #define TRACE_sSA(printlevel, level, prefix, sa, flags, suffix ) { \ 428 if ( TRACE_BOOL(level) ) { \ 429 char __buf[1024]; \ 430 sSA_DUMP_NODE_SERV(__buf, sizeof(__buf), sa, flags ); \ 431 fd_log(printlevel, "%s%s%s" , (prefix), __buf, (suffix)); \ 432 } \ 433 } 434 #endif /* DEBUG */ 391 435 392 436 /****************** … … 395 439 #ifdef STRIP_DEBUG_CODE 396 440 #undef TRACE_DEBUG 441 #undef TRACE_NOTICE 442 #undef TRACE_ERROR 397 443 #undef TRACE_BOOL 398 #undef TRACE_DEBUG_sSA 399 #undef TRACE_DEBUG_BUFFER 400 #undef TRACE_DEBUG_ERROR 401 #define TRACE_DEBUG(level,format,args... ) 402 #define TRACE_BOOL(_level_) (0) 403 #define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) 404 #define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) 405 #define TRACE_DEBUG_ERROR(format,args... ) { \ 406 fd_log(FD_LOG_ERROR, format, ## args); \ 407 } 444 #undef TRACE_BUFFER 445 #undef TRACE_sSA 446 447 #define TRACE_DEBUG(level,format,args... ) /* noop */ 448 #define TRACE_BOOL(_level_) (0) /* always false */ 449 #define TRACE_NOTICE fd_log_notice 450 #define TRACE_ERROR fd_log_error 451 #define TRACE_BUFFER(printlevel, level, prefix, buf, bufsz, suffix ) { \ 452 if (printlevel > FD_LOG_DEBUG) { \ 453 int __i; \ 454 size_t __sz = (size_t)(bufsz); \ 455 uint8_t * __buf = (uint8_t *)(buf); \ 456 char * __strbuf[1024+1]; \ 457 for (__i = 0; (__i < __sz) && (__i<(sizeof(__strbuf)/2); __i++) { \ 458 sprintf(__strbuf + (2 * __i), "%02.2hhx", __buf[__i]); \ 459 } \ 460 fd_log(printlevel, prefix"%s"suffix, __strbuf); \ 461 } 462 #define TRACE_sSA(printlevel, level, prefix, sa, flags, suffix ) { \ 463 if (printlevel > FD_LOG_DEBUG) { \ 464 char __buf[1024]; \ 465 sSA_DUMP_NODE_SERV(__buf, sizeof(__buf), sa, flags ); \ 466 fd_log(printlevel, prefix "%s" suffix, __buf); \ 467 } 408 468 #endif /* STRIP_DEBUG_CODE */ 409 469 … … 424 484 if (__ret__ < 0) { \ 425 485 int __err__ = errno; /* We may handle EINTR here */ \ 426 TRACE_ DEBUG_ERROR("ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\486 TRACE_ERROR("ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\ 427 487 __fallback__; \ 428 488 } \ … … 435 495 if (__ret__ < 0) { \ 436 496 int __err__ = errno; /* We may handle EINTR here */ \ 437 TRACE_ DEBUG_ERROR("ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\497 TRACE_ERROR("ERROR: in '" #__call__ "' :\t%s", strerror(__err__));\ 438 498 return __err__; \ 439 499 } \ … … 449 509 __fallback1__; \ 450 510 } else { \ 451 TRACE_ DEBUG_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__ret__)); \511 TRACE_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__ret__)); \ 452 512 __fallback2__; \ 453 513 } \ … … 472 532 if (__ret__ == NULL) { \ 473 533 int __err__ = errno; \ 474 TRACE_ DEBUG_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__err__)); \534 TRACE_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__err__)); \ 475 535 __fallback__; \ 476 536 } \ … … 486 546 TRACE_DEBUG_ALL( "Check PARAMS: " #__bool__ ); \ 487 547 if ( ! (__bool__) ) { \ 488 TRACE_ DEBUG_ERROR("Warning: Invalid parameter received in '" #__bool__ "'"); \548 TRACE_ERROR("Warning: Invalid parameter received in '" #__bool__ "'"); \ 489 549 __fallback__; \ 490 550 } … … 499 559 __ret__ = (__call__); \ 500 560 if (__ret__ != 0) { \ 501 TRACE_ DEBUG_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__ret__)); \561 TRACE_ERROR("ERROR: in '" #__call__ "':\t%s", strerror(__ret__)); \ 502 562 __fallback__; \ 503 563 } \
Note: See TracChangeset
for help on using the changeset viewer.