#include "kt_dbg.h" #include static int s_kt_log_level = KT_LOG_INFO; void kt_dbg_set_level(int level) { if (level < KT_LOG_VERB) { level = KT_LOG_VERB; } if (level > KT_LOG_ERROR) { level = KT_LOG_ERROR; } s_kt_log_level = level; } int kt_dbg_get_level(void) { return s_kt_log_level; } void kt_dbg_hexdump(const char *tag, const void *buf, int len) { const unsigned char *p = (const unsigned char *)buf; int i; if (buf == NULL || len <= 0) { return; } if (tag) { printf("[%s] HEXDUMP len=%d\r\n", tag, len); } else { printf("[KT] HEXDUMP len=%d\r\n", len); } for (i = 0; i < len; i++) { printf("%02x%s", p[i], ((i + 1) % 16) ? " " : "\r\n"); } if (len % 16) { printf("\r\n"); } } void kt_dbg_printf(int level, const char *tag, const char *fmt, ...) { va_list ap; if (level < s_kt_log_level) { return; } if (tag) { printf("[%s] ", tag); } else { printf("[KT] "); } va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\r\n"); }