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_Notice(char *Ident, char *Message, ...);
51 void Log_Log(char *Ident, char *Message, ...);
52 void Log_Debug(char *Ident, char *Message, ...);
53 //static Uint64 Log_Int_GetIdent(const char *Str);
56 EXPORT(Log_KernelPanic);
67 tLogList gLog_Levels[NUM_LOG_LEVELS];
71 * \brief Adds an event to the log
73 void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args)
78 if( Level >= NUM_LOG_LEVELS ) return;
80 len = vsnprintf(NULL, 256, Format, Args);
82 //Log("len = %i", len);
84 ent = malloc(sizeof(tLogEntry)+len+1);
86 strncpy(ent->Ident, Ident, 8);
89 vsnprintf( ent->Data, 256, Format, Args );
91 //Log("ent->Ident = '%s'", ent->Ident);
92 //Log("ent->Data = '%s'", ent->Data);
96 ent->Next = gLog.Tail;
100 gLog.Tail = gLog.Head = ent;
102 ent->LevelNext = gLog_Levels[Level].Tail;
103 if(gLog_Levels[Level].Head)
104 gLog_Levels[Level].Tail = ent;
106 gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent;
111 Log_Int_PrintMessage( ent );
117 * \brief Prints a log message to the debug console
119 void Log_Int_PrintMessage(tLogEntry *Entry)
121 LogF("%018lli%s [%+8s] %s\n",
123 csaLevelCodes[Entry->Level],
130 * \brief KERNEL PANIC!!!!
132 void Log_KernelPanic(char *Ident, char *Message, ...)
135 va_start(args, Message);
136 Log_AddEvent(Ident, LOG_LEVEL_KPANIC, Message, args);
141 * \brief Panic Message - Driver Unrecoverable error
143 void Log_Panic(char *Ident, char *Message, ...)
146 va_start(args, Message);
147 Log_AddEvent(Ident, LOG_LEVEL_PANIC, Message, args);
152 * \brief Error Message - Recoverable Error
154 void Log_Error(char *Ident, char *Message, ...)
157 va_start(args, Message);
158 Log_AddEvent(Ident, LOG_LEVEL_ERROR, Message, args);
163 * \brief Warning Message - Something the user should know
165 void Log_Warning(char *Ident, char *Message, ...)
169 va_start(args, Message);
170 Log_AddEvent(Ident, LOG_LEVEL_WARNING, Message, args);
175 * \brief Notice Message - Something the user might like to know
177 void Log_Notice(char *Ident, char *Message, ...)
180 va_start(args, Message);
181 Log_AddEvent(Ident, LOG_LEVEL_NOTICE, Message, args);
186 * \brief Log Message - Possibly useful information
188 void Log_Log(char *Ident, char *Message, ...)
191 va_start(args, Message);
192 Log_AddEvent(Ident, LOG_LEVEL_LOG, Message, args);
197 * \brief Debug Message - Only a developer would want this info
199 void Log_Debug(char *Ident, char *Message, ...)
202 va_start(args, Message);
203 Log_AddEvent(Ident, LOG_LEVEL_DEBUG, Message, args);