forked from piratfm/eti-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.c
97 lines (77 loc) · 1.94 KB
/
logging.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* logging.c
*
* Created on: 27 янв. 2011
* Author: tipok
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include "logging.h"
int verbosity = 1;
/*****************************************************************************
* msg_Dbg
*****************************************************************************/
void msg_Dbg( void *_unused, const char *psz_format, ... )
{
if (verbosity > 2)
{
va_list args;
char psz_fmt[MAX_MSG];
va_start( args, psz_format );
snprintf( psz_fmt, MAX_MSG, "debug: %s\n", psz_format );
vfprintf( stderr, psz_fmt, args );
}
}
/*****************************************************************************
* msg_Log
*****************************************************************************/
void msg_Log(const char *psz_format, ...)
{
va_list args;
time_t rawtime;
struct tm * timeinfo;
char psz_fmt[MAX_MSG];
int size = 0;
va_start( args, psz_format );
time(&rawtime);
timeinfo = localtime(&rawtime);
size = strftime(psz_fmt, MAX_MSG, "\x08[%x %X]", timeinfo);
snprintf(psz_fmt + size, MAX_MSG - size, " %s", psz_format);
vfprintf(stderr, psz_fmt, args);
fprintf(stderr, "\n");
}
void msg_Dump(char *bytes, int len)
{
int i;
int count;
int done = 0;
fprintf(stderr, "dump %d bytes:\n", len);
while (len > done) {
if (len-done > 32){
count = 32;
} else {
count = len-done;
}
fprintf(stderr, "\t\t\t\t");
for (i=0; i<count; i++) {
fprintf(stderr, "%02x ", (int)((unsigned char)bytes[done+i]));
}
for (; i<32; i++) {
fprintf(stderr, " ");
}
fprintf(stderr, "\t\"");
for (i=0; i<count; i++) {
fprintf(stderr, "%c", isprint(bytes[done+i]) ? bytes[done+i] : '.');
}
for (; i<32; i++) {
fprintf(stderr, " ");
}
fprintf(stderr, "\"\n");
done += count;
}
}