X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Flogging.c;h=225ce53e89884a91f04ef52a949c82446c44068e;hb=7d881c2e5fef91a6570e46ef69a5d4a5cf0e8b4d;hp=6eac2330211cb9d9cd17b337d4921306de8b57dd;hpb=7f07ccaa4d128305aed6f67f1f57a5c9276a895f;p=tpg%2Facess2.git diff --git a/Kernel/logging.c b/Kernel/logging.c index 6eac2330..225ce53e 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -7,6 +7,8 @@ #include #define PRINT_ON_APPEND 1 +#define USE_RING_BUFFER 1 +#define RING_BUFFER_SIZE 4096 // === CONSTANTS === enum eLogLevels @@ -21,7 +23,11 @@ enum eLogLevels LOG_LEVEL_DEBUG, NUM_LOG_LEVELS }; -const char *csaLevelCodes[] = {"k","p","f","e","w","n","l","d"}; +const char *csaLevelColours[] = { + "\x1B[35m", "\x1B[34m", "\x1B[36m", "\x1B[31m", + "\x1B[33m", "\x1B[32m", "\x1B[0m", "\x1B[0m" + }; +const char *csaLevelCodes[] = {"k","p","f","e","w","n","l","d"}; // === TYPES === typedef struct sLogEntry @@ -29,9 +35,9 @@ typedef struct sLogEntry struct sLogEntry *Next; struct sLogEntry *LevelNext; Sint64 Time; - char Ident[8]; int Level; int Length; + char Ident[9]; char Data[]; } tLogEntry; typedef struct sLogList @@ -50,10 +56,8 @@ void Log_Warning(char *Ident, char *Message, ...); void Log_Notice(char *Ident, char *Message, ...); void Log_Log(char *Ident, char *Message, ...); void Log_Debug(char *Ident, char *Message, ...); -//static Uint64 Log_Int_GetIdent(const char *Str); // === EXPORTS === -EXPORT(Log_KernelPanic); EXPORT(Log_Panic); EXPORT(Log_Error); EXPORT(Log_Warning); @@ -62,9 +66,15 @@ EXPORT(Log_Log); EXPORT(Log_Debug); // === GLOBALS === -tSpinlock glLog; +tShortSpinlock glLogOutput; +#if USE_RING_BUFFER +Uint8 gaLog_RingBufferData[sizeof(tRingBuffer)+RING_BUFFER_SIZE]; +tRingBuffer *gpLog_RingBuffer = (void*)gaLog_RingBufferData; +#else +tMutex glLog; tLogList gLog; tLogList gLog_Levels[NUM_LOG_LEVELS]; +#endif // === CODE === /** @@ -74,24 +84,41 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) { int len; tLogEntry *ent; + va_list args_tmp; if( Level >= NUM_LOG_LEVELS ) return; - len = vsnprintf(NULL, 256, Format, Args); + va_copy(args_tmp, Args); + len = vsnprintf(NULL, 256, Format, args_tmp); //Log("len = %i", len); + #if USE_RING_BUFFER + { + char buf[sizeof(tLogEntry)+len+1]; + ent = (void*)buf; + #else ent = malloc(sizeof(tLogEntry)+len+1); + #endif ent->Time = now(); - strncpy(ent->Ident, Ident, 7); + strncpy(ent->Ident, Ident, 8); ent->Level = Level; ent->Length = len; - vsnprintf( ent->Data, 256, Format, Args ); - - //Log("ent->Ident = '%s'", ent->Ident); - //Log("ent->Data = '%s'", ent->Data); + vsnprintf( ent->Data, len+1, Format, Args ); - LOCK( &glLog ); + #if USE_RING_BUFFER + { + #define LOG_HDR_LEN (14+1+2+8+2) + char newData[ LOG_HDR_LEN + len + 2 + 1 ]; + sprintf( newData, "%014lli%s [%+8s] ", + ent->Time, csaLevelCodes[Level], Ident); + strcpy( newData + LOG_HDR_LEN, ent->Data ); + strcpy( newData + LOG_HDR_LEN + len, "\r\n" ); + gpLog_RingBuffer->Space = RING_BUFFER_SIZE; // Needed to init the buffer + RingBuffer_Write( gpLog_RingBuffer, newData, LOG_HDR_LEN + len + 2 ); + } + #else + Mutex_Acquire( &glLog ); ent->Next = gLog.Tail; if(gLog.Head) @@ -105,12 +132,16 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) else gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent; - RELEASE( &glLog ); + Mutex_Release( &glLog ); + #endif #if PRINT_ON_APPEND Log_Int_PrintMessage( ent ); #endif + #if USE_RING_BUFFER + } + #endif } /** @@ -118,12 +149,15 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) */ void Log_Int_PrintMessage(tLogEntry *Entry) { - LogF("%018lli%s [%+8s] %s\n", + SHORTLOCK( &glLogOutput ); + LogF("%s%014lli%s [%+8s] %s\x1B[0m\r\n", + csaLevelColours[Entry->Level], Entry->Time, csaLevelCodes[Entry->Level], Entry->Ident, Entry->Data ); + SHORTREL( &glLogOutput ); } /**