X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Flogging.c;h=46d4c0494c9f3336ca4eb9671bd21faaade7a3fa;hb=5ee801f4fb22bba3298f10273027e67f53692e4c;hp=d067e499b1d82feaa1d39e4068b238add5e30bc3;hpb=11dbd684e9a3d907d43d71a3145205f1a86992fb;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/logging.c b/KernelLand/Kernel/logging.c index d067e499..46d4c049 100644 --- a/KernelLand/Kernel/logging.c +++ b/KernelLand/Kernel/logging.c @@ -29,7 +29,10 @@ 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"}; +const char *csaLevelCodes[] = { + "k","p","f","e", + "w","n","l","d" + }; // === TYPES === typedef struct sLogEntry @@ -69,14 +72,16 @@ EXPORT(Log_Debug); // === GLOBALS === tShortSpinlock glLogOutput; -#if USE_RING_BUFFER +#if CACHE_MESSAGES +# if USE_RING_BUFFER Uint8 gaLog_RingBufferData[sizeof(tRingBuffer)+RING_BUFFER_SIZE]; tRingBuffer *gpLog_RingBuffer = (void*)gaLog_RingBufferData; -#else +# else tMutex glLog; tLogList gLog; tLogList gLog_Levels[NUM_LOG_LEVELS]; -#endif +# endif // USE_RING_BUFFER +#endif // CACHE_MESSAGES // === CODE === /** @@ -89,11 +94,9 @@ void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args va_list args_tmp; if( Level >= NUM_LOG_LEVELS ) return; - + va_copy(args_tmp, Args); - len = vsnprintf(NULL, 256, Format, args_tmp); - - //Log("len = %i", len); + len = vsnprintf(NULL, 0, Format, args_tmp); #if USE_RING_BUFFER || !CACHE_MESSAGES { @@ -114,9 +117,7 @@ void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args { #define LOG_HDR_LEN (14+1+2+8+2) char newData[ LOG_HDR_LEN + len + 2 + 1 ]; - char _ident[9]; - strncpy(_ident, Ident, 9); - sprintf( newData, "%014lli%s [%-8s] ", + sprintf( newData, "%014lli%s [%-8.8s] ", ent->Time, csaLevelCodes[Level], Ident); strcpy( newData + LOG_HDR_LEN, ent->Data ); strcpy( newData + LOG_HDR_LEN + len, "\r\n" ); @@ -127,16 +128,14 @@ void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args Mutex_Acquire( &glLog ); ent->Next = gLog.Tail; - if(gLog.Head) - gLog.Tail = ent; - else - gLog.Tail = gLog.Head = ent; + tLogEntry **pnp = (gLog.Tail ? &gLog.Tail->Next : &gLog.Head); + *pnp = ent; + gLog.Tail = ent; ent->LevelNext = gLog_Levels[Level].Tail; - if(gLog_Levels[Level].Head) - gLog_Levels[Level].Tail = ent; - else - gLog_Levels[Level].Tail = gLog_Levels[Level].Head = ent; + pnp = (gLog_Levels[Level].Tail ? &gLog_Levels[Level].Tail->LevelNext : &gLog_Levels[Level].Head); + *pnp = ent; + gLog_Levels[Level].Tail = ent; Mutex_Release( &glLog ); # endif @@ -159,12 +158,15 @@ void Log_Int_PrintMessage(tLogEntry *Entry) if( CPU_HAS_LOCK(&glLogOutput) ) return ; // TODO: Error? SHORTLOCK( &glLogOutput ); - LogF("%s%014lli%s [%-8s] %i - %s", + LogF("%s%014lli", csaLevelColours[Entry->Level], - Entry->Time, + Entry->Time + ); + LogF("%s [%-8s] %i - %.*s", csaLevelCodes[Entry->Level], Entry->Ident, Threads_GetTID(), + Entry->Length, Entry->Data ); LogF("\x1B[0m\r\n"); // Separate in case Entry->Data is too long