diff options
author | Pavel Březina <pbrezina@redhat.com> | 2011-08-09 10:19:03 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-08-25 15:46:11 -0400 |
commit | a32ae272bb0ae0a47ab80d3a2fcc535fd5260754 (patch) | |
tree | 3e06169af97e8c8d27f3ea6debe1c0925e7cdc2e /src | |
parent | 24a5dc6614f3bd834d1b82c19cca8d3adc6a7653 (diff) | |
download | sssd-a32ae272bb0ae0a47ab80d3a2fcc535fd5260754.tar.gz sssd-a32ae272bb0ae0a47ab80d3a2fcc535fd5260754.tar.bz2 sssd-a32ae272bb0ae0a47ab80d3a2fcc535fd5260754.zip |
New DEBUG facility - new levels
https://fedorahosted.org/sssd/ticket/925
Added functions:
- debug_convert_old_level() to convert levels 0-9 to appropriate bitmask
debug_convert_old_level(5) returns 0x03F0 (= 0 | 1 | 2 | 3 | 4 | 5)
- debug_get_level() to convert old level number to its new value
debug_get_level(5) returns 0x0200 (= 5)
There are several new macros in util/util.h:
- SSSDBG_* to reflect a debug level (same names as in the ticket) - please,
don't use magic numbers anymore
Diffstat (limited to 'src')
-rw-r--r-- | src/util/debug.c | 70 | ||||
-rw-r--r-- | src/util/util.h | 21 |
2 files changed, 89 insertions, 2 deletions
diff --git a/src/util/debug.c b/src/util/debug.c index 89b6217e..cca92eb9 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -58,6 +58,49 @@ errno_t set_debug_file_from_fd(const int fd) return EOK; } +int debug_convert_old_level(int old_level) +{ + if ((old_level != 0) && !(old_level & 0x000F)) + return old_level; + + if( old_level == SSS_UNRESOLVED_DEBUG_LEVEL ) + return SSSDBG_UNRESOLVED; + + int new_level = SSSDBG_FATAL_FAILURE; + + if (old_level == 0) + return new_level; + + if (old_level >= 1) + new_level |= SSSDBG_CRIT_FAILURE; + + if (old_level >= 2) + new_level |= SSSDBG_OP_FAILURE; + + if (old_level >= 3) + new_level |= SSSDBG_MINOR_FAILURE; + + if (old_level >= 4) + new_level |= SSSDBG_CONF_SETTINGS; + + if (old_level >= 5) + new_level |= SSSDBG_FUNC_DATA; + + if (old_level >= 6) + new_level |= SSSDBG_TRACE_FUNC; + + if (old_level >= 7) + new_level |= SSSDBG_TRACE_LIBS; + + if (old_level >= 8) + new_level |= SSSDBG_TRACE_INTERNAL; + + if (old_level >= 9) + new_level |= SSSDBG_TRACE_ALL; + + return new_level; +} + void debug_fn(const char *format, ...) { va_list ap; @@ -70,6 +113,33 @@ void debug_fn(const char *format, ...) va_end(ap); } +int debug_get_level(int old_level) +{ + if ((old_level != 0) && !(old_level & 0x000F)) + return old_level; + + if( old_level == SSS_UNRESOLVED_DEBUG_LEVEL ) + return SSSDBG_UNRESOLVED; + + if ((old_level > 9) || (old_level < 0)) + return SSSDBG_FATAL_FAILURE; + + int levels[] = { + SSSDBG_FATAL_FAILURE, /* 0 */ + SSSDBG_CRIT_FAILURE, + SSSDBG_OP_FAILURE, + SSSDBG_MINOR_FAILURE, + SSSDBG_CONF_SETTINGS, + SSSDBG_FUNC_DATA, + SSSDBG_TRACE_FUNC, + SSSDBG_TRACE_LIBS, + SSSDBG_TRACE_INTERNAL, + SSSDBG_TRACE_ALL /* 9 */ + }; + + return levels[old_level]; +} + void ldb_debug_messages(void *context, enum ldb_debug_level level, const char *fmt, va_list ap) { diff --git a/src/util/util.h b/src/util/util.h index 3ff5f629..acaaf4da 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -57,10 +57,27 @@ extern int debug_timestamps; extern int debug_to_file; extern const char *debug_log_file; void debug_fn(const char *format, ...); +int debug_get_level(int old_level); +int debug_convert_old_level(int old_level); errno_t set_debug_file_from_fd(const int fd); -#define SSS_DEFAULT_DEBUG_LEVEL 0 -#define SSS_UNRESOLVED_DEBUG_LEVEL -1 +#define SSS_DEFAULT_DEBUG_LEVEL SSSDBG_DEFAULT +#define SSS_UNRESOLVED_DEBUG_LEVEL SSSDBG_UNRESOLVED + +#define SSSDBG_FATAL_FAILURE 0x0010 /* level 0 */ +#define SSSDBG_CRIT_FAILURE 0x0020 /* level 1 */ +#define SSSDBG_OP_FAILURE 0x0040 /* level 2 */ +#define SSSDBG_MINOR_FAILURE 0x0080 /* level 3 */ +#define SSSDBG_CONF_SETTINGS 0x0100 /* level 4 */ +#define SSSDBG_FUNC_DATA 0x0200 /* level 5 */ +#define SSSDBG_TRACE_FUNC 0x0400 /* level 6 */ +#define SSSDBG_TRACE_LIBS 0x1000 /* level 7 */ +#define SSSDBG_TRACE_INTERNAL 0x2000 /* level 8 */ +#define SSSDBG_TRACE_ALL 0x4000 /* level 9 */ + +#define SSSDBG_UNRESOLVED -1 +#define SSSDBG_MASK_ALL 0xFFF0 /* enable all debug levels */ +#define SSSDBG_DEFAULT SSSDBG_FATAL_FAILURE #define SSSDBG_TIMESTAMP_UNRESOLVED -1 #define SSSDBG_TIMESTAMP_DEFAULT 1 |