feat: owloysius - dynamic init function invocator
[lunaix-os.git] / lunaix-os / includes / lunaix / syslog.h
1 #ifndef __LUNAIX_SYSLOG_H
2 #define __LUNAIX_SYSLOG_H
3
4 #include <lunaix/compiler.h>
5 #include <stdarg.h>
6
7 #define KLOG_DEBUG 0
8 #define KLOG_INFO 1
9 #define KLOG_WARN 2
10 #define KLOG_ERROR 3
11 #define KLOG_FATAL 4
12
13 #define KMSG_LVLSTART '\x1b'
14 #define KMSG_LOGLEVEL(c) ((c) - '0')
15
16 #define KDEBUG "\x1b" stringify__(KLOG_DEBUG)
17 #define KINFO "\x1b" stringify__(KLOG_INFO)
18 #define KWARN "\x1b" stringify__(KLOG_WARN)
19 #define KERROR "\x1b" stringify__(KLOG_ERROR)
20 #define KFATAL "\x1b" stringify__(KLOG_FATAL)
21
22 #define LOG_MODULE(module)                                                     \
23     static void kprintf(const char* fmt, ...)                                  \
24     {                                                                          \
25         va_list args;                                                          \
26         va_start(args, fmt);                                                   \
27         kprintf_m(module, fmt, args);                                          \
28         va_end(args);                                                          \
29     }
30
31 #define DEBUG(fmt, ...) kprintf(KDEBUG fmt, ##__VA_ARGS__)
32 #define WARN(fmt, ...) kprintf(KWARN fmt, ##__VA_ARGS__)
33 #define ERROR(fmt, ...) kprintf(KERROR fmt, ##__VA_ARGS__)
34 #define FATAL(fmt, ...)                                                        \
35     ({                                                                         \
36         kprintf(KFATAL fmt, ##__VA_ARGS__);                                    \
37         spin();                                                                \
38     })
39
40 void
41 kprintf_m(const char* component, const char* fmt, va_list args);
42
43 // TODO need more thought on it
44
45 // struct klog_chunk
46 // {
47 //     void* log_entry;
48 //     size_t max_len;
49 //     size_t len;
50 // };
51
52 // struct klog_chunk*
53 // kprintf_lcstart_m(const char* component, size_t size);
54
55 // void
56 // kprintf_lcappend_m(struct klog_chunk*, const char* fmt, va_list args);
57
58 // void
59 // kprintf_lcdone_m(struct klog_chunk*);
60
61 #endif /* __LUNAIX_SYSLOG_H */