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, ...);
57 //static Uint64 Log_Int_GetIdent(const char *Str);
60 EXPORT(Log_KernelPanic);
71 tLogList gLog_Levels[NUM_LOG_LEVELS];
75 * \brief Adds an event to the log
77 void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args)
82 if( Level >= NUM_LOG_LEVELS ) return;
84 len = vsnprintf(NULL, 256, Format, Args);
86 //Log("len = %i", len);
88 ent = malloc(sizeof(tLogEntry)+len+1);
90 strncpy(ent->Ident, Ident, 8);
93 vsnprintf( ent->Data, 256, Format, Args );
95 //Log("ent->Ident = '%s'", ent->Ident);
96 //Log("ent->Data = '%s'", ent->Data);
100 ent->Next = gLog.Tail;
104 gLog.Tail = gLog.Head = ent;
106 ent->LevelNext = gLog_Levels[Level].Tail;
107 if(gLog_Levels[Level].Head)
108 gLog_Levels[Level].Tail = ent;
110 gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent;
115 Log_Int_PrintMessage( ent );
121 * \brief Prints a log message to the debug console
123 void Log_Int_PrintMessage(tLogEntry *Entry)
125 LogF("%s%018lli%s [%+8s] %s\x1B[0m\n",
126 csaLevelColours[Entry->Level],
128 csaLevelCodes[Entry->Level],
135 * \brief KERNEL PANIC!!!!
137 void Log_KernelPanic(char *Ident, char *Message, ...)
140 va_start(args, Message);
141 Log_AddEvent(Ident, LOG_LEVEL_KPANIC, Message, args);
146 * \brief Panic Message - Driver Unrecoverable error
148 void Log_Panic(char *Ident, char *Message, ...)
151 va_start(args, Message);
152 Log_AddEvent(Ident, LOG_LEVEL_PANIC, Message, args);
157 * \brief Error Message - Recoverable Error
159 void Log_Error(char *Ident, char *Message, ...)
162 va_start(args, Message);
163 Log_AddEvent(Ident, LOG_LEVEL_ERROR, Message, args);
168 * \brief Warning Message - Something the user should know
170 void Log_Warning(char *Ident, char *Message, ...)
174 va_start(args, Message);
175 Log_AddEvent(Ident, LOG_LEVEL_WARNING, Message, args);
180 * \brief Notice Message - Something the user might like to know
182 void Log_Notice(char *Ident, char *Message, ...)
185 va_start(args, Message);
186 Log_AddEvent(Ident, LOG_LEVEL_NOTICE, Message, args);
191 * \brief Log Message - Possibly useful information
193 void Log_Log(char *Ident, char *Message, ...)
196 va_start(args, Message);
197 Log_AddEvent(Ident, LOG_LEVEL_LOG, Message, args);
202 * \brief Debug Message - Only a developer would want this info
204 void Log_Debug(char *Ident, char *Message, ...)
207 va_start(args, Message);
208 Log_AddEvent(Ident, LOG_LEVEL_DEBUG, Message, args);