From 9df915dd5d646b39e41fe4126f8347cc18070e4c Mon Sep 17 00:00:00 2001 From: hyc Date: Tue, 29 Dec 2009 22:23:05 +0000 Subject: [PATCH] Make LogHexString() more usable, add DEBUG2 level git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@131 400ebc74-4327-4243-bc38-086b20814532 --- log.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- log.h | 7 ++++--- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/log.c b/log.c index b6be0f4..165f602 100644 --- a/log.c +++ b/log.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "log.h" @@ -121,18 +123,53 @@ void LogHex(int level, const char *data, unsigned long len) LogPrintf("\n"); } -void LogHexString(const char *data, unsigned long len) +void LogHexString(int level, const char *data, unsigned long len) { + static const char hexdig[] = "0123456789abcdef"; +#define BP_OFFSET 9 +#define BP_GRAPH 60 +#define BP_LEN 80 + char line[BP_LEN]; unsigned long i; - if ( debuglevel==LOGCRIT ) + + if ( !data || level > debuglevel ) return; - for(i=0; i> 12)]; + line[3] = hexdig[0x0f & (off >> 8)]; + line[4] = hexdig[0x0f & (off >> 4)]; + line[5] = hexdig[0x0f & off]; + line[6] = ':'; + } + + off = BP_OFFSET + n*3 + ((n >= 8)?1:0); + line[off] = hexdig[0x0f & ( data[i] >> 4 )]; + line[off+1] = hexdig[0x0f & data[i]]; + + off = BP_GRAPH + n + ((n >= 8)?1:0); + + if ( isprint( (unsigned char) data[i] )) { + line[BP_GRAPH + n] = data[i]; + } else { + line[BP_GRAPH + n] = '.'; + } } - LogPrintf("\n"); + + LogPrintf( "%s", line ); } diff --git a/log.h b/log.h index fcb035a..b16bb0c 100644 --- a/log.h +++ b/log.h @@ -39,8 +39,9 @@ extern "C" { #define LOGERROR 1 #define LOGWARNING 2 #define LOGINFO 3 -#define LOGDEBUG 4 -#define LOGALL 5 +#define LOGDEBUG 4 +#define LOGDEBUG2 5 +#define LOGALL 6 #define Log AMF_Log #define LogHex AMF_LogHex @@ -57,7 +58,7 @@ void LogPrintf(const char *format, ...); void LogStatus(const char *format, ...); void Log(int level, const char *format, ...); void LogHex(int level, const char *data, unsigned long len); -void LogHexString(const char *data, unsigned long len); +void LogHexString(int level, const char *data, unsigned long len); #ifdef __cplusplus } -- 2.50.1