3 * - By John Hodge (thePowersGang)
5 * logging.c - Kernel Logging Service
9 #define PRINT_ON_APPEND 1
24 const char *csaLevelColours[] = {
25 "\x1B[35m", "\x1B[34m", "\x1B[36m", "\x1B[31m",
26 "\x1B[33m", "\x1B[32m", "\x1B[0m", "\x1B[0m"
28 const char *csaLevelCodes[] = {"k","p","f","e","w","n","l","d"};
31 typedef struct sLogEntry
33 struct sLogEntry *Next;
34 struct sLogEntry *LevelNext;
41 typedef struct sLogList
48 void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args);
49 static void Log_Int_PrintMessage(tLogEntry *Entry);
50 void Log_KernelPanic(char *Ident, char *Message, ...);
51 void Log_Panic(char *Ident, char *Message, ...);
52 void Log_Error(char *Ident, char *Message, ...);
53 void Log_Warning(char *Ident, char *Message, ...);
54 void Log_Notice(char *Ident, char *Message, ...);
55 void Log_Log(char *Ident, char *Message, ...);
56 void Log_Debug(char *Ident, char *Message, ...);
69 tLogList gLog_Levels[NUM_LOG_LEVELS];
73 * \brief Adds an event to the log
75 void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args)
80 if( Level >= NUM_LOG_LEVELS ) return;
82 len = vsnprintf(NULL, 256, Format, Args);
84 //Log("len = %i", len);
86 ent = malloc(sizeof(tLogEntry)+len+1);
88 strncpy(ent->Ident, Ident, 8);
91 vsnprintf( ent->Data, 256, Format, Args );
93 //Log("ent->Ident = '%s'", ent->Ident);
94 //Log("ent->Data = '%s'", ent->Data);
98 ent->Next = gLog.Tail;
102 gLog.Tail = gLog.Head = ent;
104 ent->LevelNext = gLog_Levels[Level].Tail;
105 if(gLog_Levels[Level].Head)
106 gLog_Levels[Level].Tail = ent;
108 gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent;
113 Log_Int_PrintMessage( ent );
119 * \brief Prints a log message to the debug console
121 void Log_Int_PrintMessage(tLogEntry *Entry)
123 LogF("%s%018lli%s [%+8s] %s\x1B[0m\n",
124 csaLevelColours[Entry->Level],
126 csaLevelCodes[Entry->Level],
133 * \brief KERNEL PANIC!!!!
135 void Log_KernelPanic(char *Ident, char *Message, ...)
138 va_start(args, Message);
139 Log_AddEvent(Ident, LOG_LEVEL_KPANIC, Message, args);
144 * \brief Panic Message - Driver Unrecoverable error
146 void Log_Panic(char *Ident, char *Message, ...)
149 va_start(args, Message);
150 Log_AddEvent(Ident, LOG_LEVEL_PANIC, Message, args);
155 * \brief Error Message - Recoverable Error
157 void Log_Error(char *Ident, char *Message, ...)
160 va_start(args, Message);
161 Log_AddEvent(Ident, LOG_LEVEL_ERROR, Message, args);
166 * \brief Warning Message - Something the user should know
168 void Log_Warning(char *Ident, char *Message, ...)
172 va_start(args, Message);
173 Log_AddEvent(Ident, LOG_LEVEL_WARNING, Message, args);
178 * \brief Notice Message - Something the user might like to know
180 void Log_Notice(char *Ident, char *Message, ...)
183 va_start(args, Message);
184 Log_AddEvent(Ident, LOG_LEVEL_NOTICE, Message, args);
189 * \brief Log Message - Possibly useful information
191 void Log_Log(char *Ident, char *Message, ...)
194 va_start(args, Message);
195 Log_AddEvent(Ident, LOG_LEVEL_LOG, Message, args);
200 * \brief Debug Message - Only a developer would want this info
202 void Log_Debug(char *Ident, char *Message, ...)
205 va_start(args, Message);
206 Log_AddEvent(Ident, LOG_LEVEL_DEBUG, Message, args);