summaryrefslogtreecommitdiff
path: root/lib/logger/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/logger/log.c')
-rw-r--r--lib/logger/log.c68
1 files changed, 50 insertions, 18 deletions
diff --git a/lib/logger/log.c b/lib/logger/log.c
index c9bb652..4a510f9 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -1,44 +1,76 @@
-#include "log.h"
+#define FOOLOS_MODULE_NAME "log"
+
+#include "lib/logger/log.h"
#include <stdarg.h>
+
+#include "log.h"
#include "lib/int/stdint.h"
+#include "kernel/time.h"
+
+#define BUF_SIZE 4069
-void PutConsole(char *str, int color, va_list va);
+static char buffer[BUF_SIZE];
+static int first;
+static int last;
-volatile uint64_t task_system_clock; // in task.c
+void PutConsole(char *str, int color);
void log(char *module_name, int log_level, char *format_string, ...)
{
-
if(log_level<FOOLOS_LOG_INFO)return;
- char buf[10];
+
+ char buf_info[256];
+ char buf_log[256];
+ char buf_time[20];
+
uint32_t t=task_system_clock;
uint32_t s=t/25;
uint32_t ms=t*1000/25-1000*s;
- tfp_sprintf(buf,"[%6d.%05d] ",s,ms);
+ tfp_sprintf(buf_time,"[%6d.%05d] ",s,ms);
- PutConsole(buf,0b0111101111101111,task_system_clock);
- PutConsole(module_name,0b1111100000000000,0);
- PutConsole(": ",0b0000011111100000,0);
va_list va;
va_start(va,format_string);
- //PutConsole(format_string, 0b11111, va); // blue
- PutConsole(format_string, 0b0111101111111111, va);
+ tfp_vsprintf(buf_info,format_string,va);
va_end(va);
+
+ PutConsole(buf_time,0b0111101111101111);
+ PutConsole(module_name,0b1111100000000000);
+ PutConsole(": ",0b0000011111100000);
+ PutConsole(buf_info, 0b0111101111111111);
PutConsoleNL();
-
+ tfp_sprintf(buf_log,"%s %s: %s\n",buf_time,module_name,buf_info);
+
+ 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;
+ }
+
+
}
void panic(char *module_name, char *format_string)
{
-
- PutConsole("!! KERNEL PANIC !! ",0b1111100000000000,0);
- PutConsole(module_name,0b1111100000000000,0);
- PutConsole(" : ",0b0000011111100000,0);
- PutConsole(format_string,0b1111100000000000,0);
+ PutConsole("!! KERNEL PANIC !! ",0b1111100000000000);
+ PutConsole(module_name,0b1111100000000000);
+ PutConsole(" : ",0b0000011111100000);
+ PutConsole(format_string,0b1111100000000000);
while(1); // halt
-
}
+
+void log_init()
+{
+ first=last=0;
+}
+
+void log_log()
+{
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init buffer at: 0x%08X, first=%08X, last=%08X",buffer,&first,&last);
+}
+