8 #include <acess_logging.h>
12 #define LOGHDR(col,type) fprintf(stderr, "\e["col"m[%-8.8s]"type" ", Ident)
13 #define LOGTAIL() fprintf(stderr, "\e[0m\n")
15 #define PUTERR(col,type) {\
17 va_list args; va_start(args, Message);\
18 vfprintf(stderr, Message, args);\
24 void Log_KernelPanic(const char *Ident, const char *Message, ...) {
28 void Log_Panic(const char *Ident, const char *Message, ...)
30 void Log_Error(const char *Ident, const char *Message, ...)
32 void Log_Warning(const char *Ident, const char *Message, ...)
34 void Log_Notice(const char *Ident, const char *Message, ...)
36 void Log_Log(const char *Ident, const char *Message, ...)
38 void Log_Debug(const char *Ident, const char *Message, ...)
41 void Warning(const char *Message, ...) {
42 const char *Ident = "";
45 void Log(const char *Message, ...) {
46 const char *Ident = "";
50 void Debug_HexDump(const char *Prefix, const void *Data, size_t Length)
52 const uint8_t *data = Data;
54 fprintf(stderr, "[HexDump ]d %s: %i bytes\n", Prefix, (int)Length);
55 for( ofs = 0; ofs + 16 <= Length; ofs += 16 )
57 fprintf(stderr, "[HexDump ]d %s:", Prefix);
58 fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
59 data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
61 fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
62 data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
64 fprintf(stderr, "\n");
67 fprintf(stderr, "[HexDump ]d %s:", Prefix);
68 for( ; ofs < Length; ofs ++ )
70 if( ofs % 8 == 0 ) fprintf(stderr, " ");
71 fprintf(stderr, " %02x", data[ofs%16]);
73 fprintf(stderr, "\n");
76 int giDebug_TraceLevel = 0;
78 void Debug_TraceEnter(const char *Function, const char *Format, ...)
80 const char *Ident = "Trace";
82 for( int i = 0; i < giDebug_TraceLevel; i ++ )
84 fprintf(stderr, "%s: (", Function);
87 va_start(args, Format);
92 while( *Format && isblank(*Format) )
96 char type = *Format++;
97 const char *start = Format;
98 while( *Format && !isblank(*Format) )
102 fprintf(stderr, ",");
105 fprintf(stderr, "%.*s=", (int)(Format-start), start);
109 fprintf(stderr, "%p", va_arg(args,const void *));
112 fprintf(stderr, "\"%s\"", va_arg(args,const char *));
115 fprintf(stderr, "%i", va_arg(args,int));
118 fprintf(stderr, "0x%x", va_arg(args,unsigned int));
121 fprintf(stderr, "0x%"PRIx64, va_arg(args,uint64_t));
124 va_arg(args,uintptr_t);
125 fprintf(stderr, "?");
132 fprintf(stderr, ")");
134 giDebug_TraceLevel ++;
137 void Debug_TraceLog(const char *Function, const char *Format, ...)
139 const char *Ident = "Trace";
142 for( int i = 0; i < giDebug_TraceLevel; i ++ )
143 fprintf(stderr, " ");
144 fprintf(stderr, "%s: ", Function);
147 va_start(args, Format);
149 vfprintf(stderr, Format, args);
155 void Debug_TraceLeave(const char *Function, char Type, ...)
157 if( giDebug_TraceLevel == 0 ) {
158 Log_Error("Debug", "Function %s called LEAVE without ENTER", Function);
161 const char *Ident = "Trace";
165 va_start(args, Type);
167 if( giDebug_TraceLevel > 0 )
169 giDebug_TraceLevel --;
170 for( int i = 0; i < giDebug_TraceLevel; i ++ )
171 fprintf(stderr, " ");
173 fprintf(stderr, "%s: RETURN", Function);
179 fprintf(stderr, " %i", va_arg(args, int));
182 fprintf(stderr, " 0x%x", va_arg(args, unsigned int));
185 fprintf(stderr, " 0x%"PRIx64, va_arg(args,uint64_t));
188 fprintf(stderr, " \"%s\"", va_arg(args, const char *));
191 fprintf(stderr, " %p", va_arg(args, const void *));
194 fprintf(stderr, " NULL");
197 fprintf(stderr, " ?");