mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Improve dump() logging primitive
This commit is contained in:
parent
ddc17434c4
commit
dbef192513
7
log.c
7
log.c
@ -232,11 +232,12 @@ void vlogMessage(int level, const char *file, unsigned int line, const char *fun
|
||||
}
|
||||
}
|
||||
|
||||
int dump(char *name, unsigned char *addr, size_t len)
|
||||
int logDump(int level, const char *file, unsigned int line, const char *function, char *name, unsigned char *addr, size_t len)
|
||||
{
|
||||
char buf[100];
|
||||
size_t i;
|
||||
DEBUGF("Dump of %s", name);
|
||||
if (name)
|
||||
logMessage(level, file, line, function, "Dump of %s", name);
|
||||
for(i = 0; i < len; i += 16) {
|
||||
strbuf b = strbuf_local(buf, sizeof buf);
|
||||
strbuf_sprintf(b, " %04x :", i);
|
||||
@ -248,7 +249,7 @@ int dump(char *name, unsigned char *addr, size_t len)
|
||||
strbuf_puts(b, " ");
|
||||
for (j = 0; j < 16 && i + j < len; j++)
|
||||
strbuf_sprintf(b, "%c", addr[i+j] >= ' ' && addr[i+j] < 0x7f ? addr[i+j] : '.');
|
||||
DEBUG(strbuf_str(b));
|
||||
logMessage(level, file, line, function, "%s", strbuf_str(b));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
4
log.h
4
log.h
@ -66,7 +66,7 @@ void logArgv(int level, const char *file, unsigned int line, const char *functio
|
||||
void logMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, ...);
|
||||
void vlogMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, va_list);
|
||||
unsigned int debugFlagMask(const char *flagname);
|
||||
int dump(char *name, unsigned char *addr, size_t len);
|
||||
int logDump(int level, const char *file, unsigned int line, const char *function, char *name, unsigned char *addr, size_t len);
|
||||
char *toprint(char *dstStr, ssize_t dstChars, const char *srcBuf, size_t srcBytes);
|
||||
size_t toprint_strlen(ssize_t dstStrLen, const char *srcBuf, size_t srcBytes);
|
||||
ssize_t get_self_executable_path(char *buf, size_t len);
|
||||
@ -106,6 +106,8 @@ int log_backtrace(const char *file, unsigned int line, const char *function);
|
||||
#define D DEBUG("D")
|
||||
#define DEBUG_argv(X,ARGC,ARGV) logArgv(LOG_LEVEL_DEBUG, __FILE__, __LINE__, __FUNCTION__, (X), (ARGC), (ARGV))
|
||||
|
||||
#define dump(X,A,N) logDump(LOG_LEVEL_DEBUG, __FILE__, __LINE__, __FUNCTION__, (X), (A), (N))
|
||||
|
||||
#define BACKTRACE log_backtrace(__FILE__, __LINE__, __FUNCTION__)
|
||||
|
||||
#endif // __SERVALD_LOG_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user