Navigation


Changeset 941:64088de91f7f in freeDiameter for include


Ignore:
Timestamp:
Jan 20, 2013, 1:42:12 AM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Initial logging rework by Thomas

File:
1 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/libfdproto.h

    r907 r941  
    110110
    111111/*
    112  * FUNCTION:    fd_log_debug_fstr
     112 * FUNCTION:    fd_log
    113113 * MACRO:       fd_log_debug
    114114 *
    115115 * PARAMETERS:
    116  *  fstr        : Stream where the text will be sent (default: stdout)
     116 *  loglevel    : Integer, how important the message is
    117117 *  format      : Same format string as in the printf function
    118118 *  ...         : Same list as printf
    119119 *
    120120 * DESCRIPTION:
    121  *  Log internal information for use of developpers only.
     121 * Write information to log.
    122122 * The format and arguments may contain UTF-8 encoded data. The
    123  * output medium (file or console) is expected to support this encoding.
     123 * output medium is expected to support this encoding.
    124124 *
    125125 * RETURN VALUE:
    126126 *  None.
    127127 */
    128 void fd_log_debug_fstr ( FILE * fstr, const char * format, ... );
    129 #define fd_log_debug(format,args...) fd_log_debug_fstr(NULL, format, ## args)
     128void fd_log ( int, const char *, ... );
     129#define fd_log_debug(format,args...) fd_log(FD_LOG_DEBUG, format, ## args)
     130void fd_log_debug_fstr( FILE *, const char *, ... );
    130131
    131132/* these are internal objects of the debug facility,
     
    174175 *
    175176 * PARAMETERS:
    176  *  fstr        : Stream where the text will be sent to (default: stdout)
     177 *  loglevel    : priority of the message
    177178 *  format      : Same format string as in the printf function
    178179 *  va_list     : Argument list
     
    184185 * int          : Success or failure
    185186 */
    186 int fd_log_handler_register ( void (*logger)(const char * format, va_list *args) );
     187int fd_log_handler_register ( void (*logger)(int loglevel, const char * format, va_list args) );
    187188
    188189/*
     
    209210#endif /* ASSERT */
    210211
    211 /* levels definitions */
     212/* log levels definitions */
     213#define FD_LOG_DEBUG 0
     214#define FD_LOG_ERROR 5
     215
     216/* print level definitions */
    212217#define NONE 0  /* Display no debug message */
    213218#define INFO 1  /* Display errors only */
     
    264269                char __buf[25];                                                                                                 \
    265270                const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                 \
    266                 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
    267                           "\t%s|%*s" format "\n",                                                                               \
     271                fd_log(level, "\t | tid:%-20s\t%s\tin %s@%s:%d\n"  \
     272                          "\t%s|%*s" format,                                                                            \
    268273                                        __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\
    269274                                        (level < FULL)?"@":" ",level, "", ## args);                                             \
     
    277282                        char __buf[25];                                                                                                 \
    278283                        const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                 \
    279                         fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
    280                                   "\t%s|%*s" format "\n",                                                                               \
     284                        fd_log(level, "\t | tid:%-20s\t%s\tin %s@%s:%d\n" \
     285                                  "\t%s|%*s" format,                                                                            \
    281286                                                __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\
    282287                                                (level < FULL)?"@":" ",level, "", ## args);                                             \
    283288                } else {                                                                                                                \
    284                         fd_log_debug(format "\n", ## args);                                                                             \
     289                        fd_log(level, format, ## args);           \
    285290                }                                                                                                                       \
    286291        }                                                                                                                               \
     
    321326                uint8_t * __buf = (uint8_t *)(buf);                                                                             \
    322327                char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                       \
    323                 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
     328                fd_log(level, "\t | tid:%-20s\t%s\tin %s@%s:%d\n"  \
    324329                          "\t%s|%*s" prefix ,                                                                                   \
    325330                                        __thn, fd_log_time(NULL, __ts, sizeof(__ts)), __PRETTY_FUNCTION__, __FILE__, __LINE__,  \
    326331                                        (level < FULL)?"@":" ",level, "");                                                      \
    327332                for (__i = 0; __i < __sz; __i++) {                                                                              \
    328                         fd_log_debug("%02.2hhx", __buf[__i]);                                                                   \
     333                        fd_log(level, "%02.2hhx", __buf[__i]);         \
    329334                }                                                                                                               \
    330                 fd_log_debug(suffix "\n");                                                                                      \
     335                fd_log(level, suffix);                        \
    331336        }                                                                                                                       \
    332337}
     
    357362                        flag);                                  \
    358363          if (__rc)                                             \
    359                 fd_log_debug("%s", (char *)gai_strerror(__rc)); \
     364                fd_log_debug("%s", (char *)gai_strerror(__rc)); \
    360365          else                                                  \
    361                 fd_log_debug("%s", &__addrbuf[0]);              \
     366                fd_log_debug("%s", &__addrbuf[0]);              \
    362367        } else {                                                \
    363                 fd_log_debug("(NULL / ANY)");                   \
     368                fd_log_debug("(NULL / ANY)");                   \
    364369        }                                                       \
    365370}
     
    378383                        flag);                                          \
    379384          if (__rc)                                                     \
    380                 fd_log_debug("%s", (char *)gai_strerror(__rc));         \
     385                fd_log_debug("%s", (char *)gai_strerror(__rc));         \
    381386          else                                                          \
    382                 fd_log_debug("[%s]:%s", &__addrbuf[0],&__servbuf[0]);   \
     387                fd_log_debug("[%s]:%s", &__addrbuf[0],&__servbuf[0]);   \
    383388        } else {                                                        \
    384389                fd_log_debug("(NULL / ANY)");                           \
     
    391396                char __buf[25];                                                                                                 \
    392397                char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                       \
    393                 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
     398                fd_log(level, "\t | tid:%-20s\t%s\tin %s@%s:%d\n"  \
    394399                          "\t%s|%*s" prefix ,                                                                                   \
    395400                                        __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\
    396401                                        (level < FULL)?"@":" ",level, "");                                                      \
    397402                sSA_DUMP_NODE_SERV( sa, flags );                                                                                \
    398                 fd_log_debug(suffix "\n");                                                                                      \
     403                fd_log(level, suffix);                        \
    399404        }                                                                                                                       \
    400405}
     
    418423#define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix )
    419424#define TRACE_DEBUG_ERROR(format,args... ) {    \
    420         fd_log_debug(format "\n", ## args);     \
     425        fd_log(FD_LOG_ERROR, format, ## args);  \
    421426}
    422427#endif /* STRIP_DEBUG_CODE */
Note: See TracChangeset for help on using the changeset viewer.