3 * - By John Hodge (thePowersGang)
5 * logging.c - Kernel Logging Service
9 #define PRINT_ON_APPEND 1
24 const char csaLevelCodes[] = {'k','p','f','e','w','n','l','d'};
27 typedef struct sLogEntry
29 struct sLogEntry *Next;
30 struct sLogEntry *LevelNext;
37 typedef struct sLogList
44 void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args);
45 static void Log_Int_PrintMessage(tLogEntry *Entry);
46 void Log_KernelPanic(char *Ident, char *Message, ...);
47 void Log_Panic(char *Ident, char *Message, ...);
48 void Log_Error(char *Ident, char *Message, ...);
49 void Log_Warning(char *Ident, char *Message, ...);
50 void Log_Log(char *Ident, char *Message, ...);
51 void Log_Notice(char *Ident, char *Message, ...);
52 void Log_Debug(char *Ident, char *Message, ...);
53 static Uint64 Log_Int_GetIdent(const char *Str);
58 tLogList gLog_Levels[NUM_LOG_LEVELS];
62 * \brief Adds an event to the log
64 void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args)
68 Uint64 ident = Log_Int_GetIdent(Ident);
70 if( Level >= NUM_LOG_LEVELS ) return;
72 len = vsnprintf(NULL, 256, Format, Args);
74 ent = malloc(sizeof(tLogEntry)+len+1);
79 vsnprintf( ent->Data, 256, Format, Args );
83 ent->Next = gLog.Tail;
87 gLog.Tail = gLog.Head = ent;
89 ent->LevelNext = gLog_Levels[Level].Tail;
90 if(gLog_Levels[Level].Head)
91 gLog_Levels[Level].Tail = ent;
93 gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent;
98 Log_Int_PrintMessage( ent );
104 * \brief Prints a log message to the debug console
106 void Log_Int_PrintMessage(tLogEntry *Entry)
108 LogF("%018%c [%8s] %s\n",
110 csaLevelCodes[Entry->Level],
117 * \brief KERNEL PANIC!!!!
119 void Log_KernelPanic(char *Ident, char *Message, ...)
122 va_start(args, Message);
123 Log_AddEvent(Ident, LOG_LEVEL_KPANIC, Message, args);
128 * \brief Panic Message - Driver Unrecoverable error
130 void Log_Panic(char *Ident, char *Message, ...)
133 va_start(args, Message);
134 Log_AddEvent(Ident, LOG_LEVEL_PANIC, Message, args);
139 * \brief Error Message - Recoverable Error
141 void Log_Error(char *Ident, char *Message, ...)
144 va_start(args, Message);
145 Log_AddEvent(Ident, LOG_LEVEL_ERROR, Message, args);
150 * \brief Warning Message - Something the user should know
152 void Log_Warning(char *Ident, char *Message, ...)
156 va_start(args, Message);
157 Log_AddEvent(Ident, LOG_LEVEL_WARNING, Message, args);
162 * \brief Notice Message - Something the user might like to know
164 void Log_Notice(char *Ident, char *Message, ...)
167 va_start(args, Message);
168 Log_AddEvent(Ident, LOG_LEVEL_NOTICE, Message, args);
173 * \brief Log Message - Possibly useful information
175 void Log_Log(char *Ident, char *Message, ...)
178 va_start(args, Message);
179 Log_AddEvent(Ident, LOG_LEVEL_LOG, Message, args);
184 * \brief Debug Message - Only a developer would want this info
186 void Log_Debug(char *Ident, char *Message, ...)
189 va_start(args, Message);
190 Log_AddEvent(Ident, LOG_LEVEL_DEBUG, Message, args);
195 * \brief Converts a string into a 64-bit ident
197 static Uint64 Log_Int_GetIdent(const char *Str)
203 for( i = 0; Str[i] && i < 7; i++ )
212 ret |= (Uint64)ch << 8*i;
216 ret |= 0x20 << (8*i);