diff options
author | Pavel Březina <pbrezina@redhat.com> | 2011-08-09 10:23:15 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-08-25 15:46:11 -0400 |
commit | 267bdd44fc55e064412177b7a67c7a047c912177 (patch) | |
tree | e98b9c3680c8c4c5be63b228603a231400529f58 /src/util/util.h | |
parent | a32ae272bb0ae0a47ab80d3a2fcc535fd5260754 (diff) | |
download | sssd-267bdd44fc55e064412177b7a67c7a047c912177.tar.gz sssd-267bdd44fc55e064412177b7a67c7a047c912177.tar.bz2 sssd-267bdd44fc55e064412177b7a67c7a047c912177.zip |
New DEBUG facility - modified DEBUG
https://fedorahosted.org/sssd/ticket/925
Modified: DEBUG() macro to work with new levels
There are several new macros in util/util.h:
- DEBUG_MSG(level, function, message) which will format the debug message
like "(time) [prg_name] [function] (level): message\n"
- DEBUG_IS_SET(level) that you should use to check if the level is allowed
to be logged
You can use it like: if (DEBUG_IS_SET(SSSDBG_TRACE_LIBS)) {...}
Diffstat (limited to 'src/util/util.h')
-rw-r--r-- | src/util/util.h | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/util/util.h b/src/util/util.h index acaaf4da..f1f1c634 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -93,7 +93,8 @@ errno_t set_debug_file_from_fd(const int fd); /** \def DEBUG(level, body) \brief macro to generate debug messages - \param level the debug level, please respect the following guidelines: + \param level the debug level, please use one of the SSSDBG_* macros + Old format: - 1 is for critical errors users may find it difficult to understand but are still quite clear - 2-4 is for stuff developers are interested in in general, but @@ -105,22 +106,56 @@ errno_t set_debug_file_from_fd(const int fd); \param body the debug message you want to send, should end with \n */ #define DEBUG(level, body) do { \ - if (level <= debug_level) { \ + int __debug_macro_newlevel = debug_get_level(level); \ + if (DEBUG_IS_SET(__debug_macro_newlevel)) { \ if (debug_timestamps) { \ time_t rightnow = time(NULL); \ char stamp[25]; \ memcpy(stamp, ctime(&rightnow), 24); \ stamp[24] = '\0'; \ - debug_fn("(%s) [%s] [%s] (%d): ", \ - stamp, debug_prg_name, __FUNCTION__, level); \ + debug_fn("(%s) [%s] [%s] (%#.4x): ", \ + stamp, debug_prg_name, __FUNCTION__, __debug_macro_newlevel); \ } else { \ - debug_fn("[%s] [%s] (%d): ", \ - debug_prg_name, __FUNCTION__, level); \ + debug_fn("[%s] [%s] (%#.4x): ", \ + debug_prg_name, __FUNCTION__, __debug_macro_newlevel); \ } \ debug_fn body; \ } \ } while(0); +/** \def DEBUG_MSG(level, function, message) + \brief macro to generate debug messages with message from variable + + \param level the debug level, please use one of the SSSDBG_* macros + + \param function name of the function where DEBUG_MSG is called + + \param message message to be send (should not end with \n) +*/ +#define DEBUG_MSG(level, function, message) do { \ + int __debug_macro_newlevel = debug_get_level(level); \ + if (DEBUG_IS_SET(__debug_macro_newlevel)) { \ + if (debug_timestamps) { \ + time_t rightnow = time(NULL); \ + char stamp[25]; \ + memcpy(stamp, ctime(&rightnow), 24); \ + stamp[24] = '\0'; \ + debug_fn("(%s) [%s] [%s] (%#.4x): %s\n", \ + stamp, debug_prg_name, function, __debug_macro_newlevel, message); \ + } else { \ + debug_fn("[%s] [%s] (%#.4x): %s\n", \ + debug_prg_name, function, __debug_macro_newlevel, message); \ + } \ + } \ +} while(0); + +/** \def DEBUG_IS_SET(level) + \brief checks whether level (must be in new format) is set in debug_level + + \param level the debug level, please use one of the SSSDBG*_ macros +*/ +#define DEBUG_IS_SET(level) ((debug_level > 0) && (debug_level & (level))) + #define PRINT(fmt, ...) fprintf(stdout, gettext(fmt), ##__VA_ARGS__) #define ERROR(fmt, ...) fprintf(stderr, gettext(fmt), ##__VA_ARGS__) |