From 0fc4c75532338d85d9aca4281f3da66e2cd8aed2 Mon Sep 17 00:00:00 2001 From: zhongyic00 <zhong200234@outlook.com> Date: Tue, 4 Jul 2023 00:02:47 +0800 Subject: [PATCH] fix: shorter func in log; feat: cofigurable log serial output --- include/klib.hh | 1 + include/macros.h | 4 ++-- utils/klib.cc | 4 +++- utils/klibc.cc | 2 -- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/klib.hh b/include/klib.hh index 0948ac5..c2e96f4 100644 --- a/include/klib.hh +++ b/include/klib.hh @@ -350,6 +350,7 @@ class Logger{ klib::ringbuf<LogItem> ring[5]; int lid=0; public: + LogLevel outputLevel=LogLevel::info; void log(int level,const char *fmt,...); }; extern Logger kLogger; diff --git a/include/macros.h b/include/macros.h index a515569..a9ec917 100644 --- a/include/macros.h +++ b/include/macros.h @@ -16,11 +16,11 @@ enum LogLevel{ #define TRACE(x) IFDEF(moduleLevel<=LogLevel::trace,x) #define IFTEST(x) IFDEF(GUEST,x) -extern int outputLevel; +extern int enableLevel; #ifndef moduleLevel #define moduleLevel LogLevel::error #endif #define Log(level,fmt,...) \ - if(level>=outputLevel && level>=moduleLevel){kLogger.log(level,(__FILE__":%d:%s::\t" fmt "\n"),__LINE__,__PRETTY_FUNCTION__,##__VA_ARGS__);} + if(level>=enableLevel && level>=moduleLevel){kLogger.log(level,(__FILE__":%d:%s::\t" fmt "\n"),__LINE__,__FUNCTION__,##__VA_ARGS__);} #define DEBUG 0 \ No newline at end of file diff --git a/utils/klib.cc b/utils/klib.cc index 21b9a61..da2386b 100644 --- a/utils/klib.cc +++ b/utils/klib.cc @@ -2,6 +2,8 @@ #include "klib.hh" #include "sbi.hh" +int enableLevel=LogLevel::info; + void IO::_sbiputs(const char *s){ size_t len=strlen(s); sbi_debug_console_write(len,(xlen_t)s,0); @@ -15,7 +17,7 @@ void Logger::log(int level,const char *fmt,...){ va_start(vl,fmt); _vsnprintf(item.buf,300,fmt,vl); va_end(vl); - if(level>=LogLevel::warning)puts(item.buf); + if(level>=outputLevel)puts(item.buf); } void EASTL_DEBUG_BREAK(){ExecInst(ebreak);} diff --git a/utils/klibc.cc b/utils/klibc.cc index c985abe..45eb9ee 100644 --- a/utils/klibc.cc +++ b/utils/klibc.cc @@ -3,8 +3,6 @@ #include "klib.h" #include "alloc.hh" -int outputLevel=LogLevel::error; - void (*puts)(const char *s); int putchar(char c){ -- GitLab