DiskTool - Cleanup, copy command
[tpg/acess2.git] / Tools / DiskTool / src / logging.c
1 /*
2  * 
3  */
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <stdlib.h>
7 #include <stdint.h>
8 #include <acess_logging.h>
9
10 #define PUTERR(col,type)        {\
11         fprintf(stderr, "\e["col"m[%-8.8s]"type" ", Ident); \
12         va_list args; va_start(args, Message);\
13         vfprintf(stderr, Message, args);\
14         va_end(args);\
15         fprintf(stderr, "\e[0m\n"); \
16 }
17
18 // === CODE ===
19 void Log_KernelPanic(const char *Ident, const char *Message, ...) {
20         PUTERR("35", "k")
21         exit(-1);
22 }
23 void Log_Panic(const char *Ident, const char *Message, ...)
24         PUTERR("34", "p")
25 void Log_Error(const char *Ident, const char *Message, ...)
26         PUTERR("31", "e")
27 void Log_Warning(const char *Ident, const char *Message, ...)
28         PUTERR("33", "w")
29 void Log_Notice(const char *Ident, const char *Message, ...)
30         PUTERR("32", "n")
31 void Log_Log(const char *Ident, const char *Message, ...)
32         PUTERR("37", "l")
33 void Log_Debug(const char *Ident, const char *Message, ...)
34         PUTERR("37", "d")
35
36 void Warning(const char *Message, ...) {
37         const char *Ident = "";
38         PUTERR("33", "W")
39 }
40 void Log(const char *Message, ...) {
41         const char *Ident = "";
42         PUTERR("37", "L")
43 }
44
45 void Debug_HexDump(const char *Prefix, const void *Data, size_t Length)
46 {
47         const uint8_t *data = Data;
48         size_t  ofs;
49         fprintf(stderr, "[HexDump ]d %s: %i bytes\n", Prefix, (int)Length);
50         for( ofs = 0; ofs + 16 <= Length; ofs += 16 )
51         {
52                 fprintf(stderr, "[HexDump ]d %s:", Prefix);
53                 fprintf(stderr, "  %02x %02x %02x %02x %02x %02x %02x %02x",
54                         data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
55                 data += 8;
56                 fprintf(stderr, "  %02x %02x %02x %02x %02x %02x %02x %02x",
57                         data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
58                 data += 8;
59                 fprintf(stderr, "\n");
60         }
61         
62         fprintf(stderr, "[HexDump ]d %s:", Prefix);
63         for( ; ofs < Length; ofs ++ )
64         {
65                 if( ofs % 16 == 8 )     fprintf(stderr, " ");
66                 fprintf(stderr, " %02x", data[ofs%16]);
67         }
68         fprintf(stderr, "\n");
69 }
70

UCC git Repository :: git.ucc.asn.au