diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/logger/log.c | 44 | ||||
| -rw-r--r-- | lib/logger/log.h | 3 |
2 files changed, 20 insertions, 27 deletions
diff --git a/lib/logger/log.c b/lib/logger/log.c index a9b2165..703658a 100644 --- a/lib/logger/log.c +++ b/lib/logger/log.c @@ -1,39 +1,45 @@ #define FOOLOS_MODULE_NAME "log" -#include "lib/logger/log.h" #include <stdarg.h> #include "log.h" +#include "kernel/config.h" #include "kernel/console.h" #include "lib/printf/printf.h" -#include "kernel/config.h" #include "lib/int/stdint.h" -#include "kernel/time.h" +#include "lib/bool/bool.h" +#include "kernel/timer.h" -#define BUF_SIZE 4069 -static char buffer[BUF_SIZE]; -static int first; -static int last; +static char buffer[LOG_BUF_SIZE]; +static int first=0; +static int last=0; +static bool init=false; void log(char *module_name, int log_level, char *format_string, ...) { + #ifdef FOOLOS_LOG_OFF return; #endif - if(log_level<FOOLOS_LOG_INFO)return; + if(!init) + { + init=true; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"buffer: 0x%08X, first=%08X, last=%08X",buffer,&first,&last); + } + char buf_info[256]; char buf_log[256]; char buf_time[20]; - uint32_t t=task_system_clock; + uint32_t t=timer_get_ticks(); uint32_t s=t/25; uint32_t ms=t*1000/25-1000*s; - tfp_sprintf(buf_time,"[%6d.%05d] ",s,ms); + tfp_sprintf(buf_time,"[%3d.%05d] ",s,ms); va_list va; va_start(va,format_string); @@ -46,9 +52,9 @@ void log(char *module_name, int log_level, char *format_string, ...) for(int i=0;buf_log[i]!=0;i++) { buffer[last]=buf_log[i]; - last=(last+1)%BUF_SIZE; - if(first<last)if(last-first>=BUF_SIZE)first=(first+1)%BUF_SIZE; - if(last>first)if(BUF_SIZE-last+first>=BUF_SIZE)first=(first+1)%BUF_SIZE; + last=(last+1)%LOG_BUF_SIZE; + if(first<last)if(last-first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; + if(last>first)if(LOG_BUF_SIZE-last+first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; } @@ -57,23 +63,11 @@ void log(char *module_name, int log_level, char *format_string, ...) void panic(char *module_name, char *message) { char buf_log[256]; - /* - PutConsole("!! KERNEL PANIC !! ",0b1111100000000000); - PutConsole(module_name,0b1111100000000000); - PutConsole(" : ",0b0000011111100000); - PutConsole(format_string,0b1111100000000000); - */ tfp_sprintf(buf_log,"KERNEL PANIC !! %s: %s\n",module_name,message); console_put_str(buf_log); - while(1); // halt } -void log_init() -{ - first=last=0; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init buffer at: 0x%08X, first=%08X, last=%08X",buffer,&first,&last); -} void log_log() { diff --git a/lib/logger/log.h b/lib/logger/log.h index 1159d94..bbe4c64 100644 --- a/lib/logger/log.h +++ b/lib/logger/log.h @@ -1,5 +1,5 @@ #ifndef FOOLOS_LOG_H -#define FOOLOS_LOGL_H +#define FOOLOS_LOG_H #define FOOLOS_LOG_INFO 3 #define FOOLOS_LOG_DEBUG 2 @@ -7,7 +7,6 @@ void log(char *module_name, int prio, char *format_string, ...); void panic(char *module_name, char *format_string); -void log_init(); void log_log(); #endif |
