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, ...);
68 tSpinlock glLogOutput;
70 tLogList gLog_Levels[NUM_LOG_LEVELS];
74 * \brief Adds an event to the log
76 void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args)
81 if( Level >= NUM_LOG_LEVELS ) return;
83 len = vsnprintf(NULL, 256, Format, Args);
85 //Log("len = %i", len);
87 ent = malloc(sizeof(tLogEntry)+len+1);
89 strncpy(ent->Ident, Ident, 8);
92 vsnprintf( ent->Data, 256, Format, Args );
94 //Log("ent->Ident = '%s'", ent->Ident);
95 //Log("ent->Data = '%s'", ent->Data);
99 ent->Next = gLog.Tail;
103 gLog.Tail = gLog.Head = ent;
105 ent->LevelNext = gLog_Levels[Level].Tail;
106 if(gLog_Levels[Level].Head)
107 gLog_Levels[Level].Tail = ent;
109 gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent;
114 Log_Int_PrintMessage( ent );
120 * \brief Prints a log message to the debug console
122 void Log_Int_PrintMessage(tLogEntry *Entry)
124 LogF("%s%018lli%s [%+8s] %s\x1B[0m\n",
125 csaLevelColours[Entry->Level],
127 csaLevelCodes[Entry->Level],
134 * \brief KERNEL PANIC!!!!
136 void Log_KernelPanic(char *Ident, char *Message, ...)
139 va_start(args, Message);
140 Log_AddEvent(Ident, LOG_LEVEL_KPANIC, Message, args);
145 * \brief Panic Message - Driver Unrecoverable error
147 void Log_Panic(char *Ident, char *Message, ...)
150 va_start(args, Message);
151 Log_AddEvent(Ident, LOG_LEVEL_PANIC, Message, args);
156 * \brief Error Message - Recoverable Error
158 void Log_Error(char *Ident, char *Message, ...)
161 va_start(args, Message);
162 Log_AddEvent(Ident, LOG_LEVEL_ERROR, Message, args);
167 * \brief Warning Message - Something the user should know
169 void Log_Warning(char *Ident, char *Message, ...)
173 va_start(args, Message);
174 Log_AddEvent(Ident, LOG_LEVEL_WARNING, Message, args);
179 * \brief Notice Message - Something the user might like to know
181 void Log_Notice(char *Ident, char *Message, ...)
184 va_start(args, Message);
185 Log_AddEvent(Ident, LOG_LEVEL_NOTICE, Message, args);
190 * \brief Log Message - Possibly useful information
192 void Log_Log(char *Ident, char *Message, ...)
195 va_start(args, Message);
196 Log_AddEvent(Ident, LOG_LEVEL_LOG, Message, args);
201 * \brief Debug Message - Only a developer would want this info
203 void Log_Debug(char *Ident, char *Message, ...)
206 va_start(args, Message);
207 Log_AddEvent(Ident, LOG_LEVEL_DEBUG, Message, args);