summaryrefslogtreecommitdiff
path: root/kernel/log.c
blob: af6ebacbb53e747a8bba552986ff418d8970f3d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "log.h"
#include "kernel.h"


#include <stdarg.h>
#include <stdbool.h>

#include "spinlock.h"

#include "kernel/kernel.h"
#include "driver/serial.h"
#include "driver/timer.h"

#include "lib/string/string.h"
#include "lib/printf/printf.h"

static void log_string(char *str)
{
//        if(get_max_fd()>=2)   syscall_write(2,str,strlen(str));
	while(*str!=0)
	{
	    serial_write(*str++);
	}
}

void log(bool color,char *module_name, int prio, char *format_string, ...)
{   
    #ifdef FOOLOS_LOG_OFF
	return;
    #endif

    char buf_info[256];
    char buf_log[256];
    char buf_time[20];

    uint64_t t=timer_get_uptime_ms();
    uint32_t ms=t%1000;
    uint32_t s=t/1000;

    tfp_sprintf(buf_time,"[%04d %03d]",s,ms);

    va_list va;
    va_start(va,format_string);
    tfp_vsprintf(buf_info,format_string,va);
    va_end(va);

    if(color) tfp_sprintf(buf_log,"\033[36;40m%s\033[31;40m %s:\033[37;40m %s\n",buf_time,module_name,buf_info);
    else tfp_sprintf(buf_log,"%s %s: %s\n",buf_time,module_name,buf_info);

//    spinlock_spin(SPINLOCK_LOG);
    log_string(buf_log);
//    spinlock_release(SPINLOCK_LOG);
}