add btrie_map() for allocating free slot, remove isrm
[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 <lunaix/spike.h>
6 #include <stdarg.h>
7
8 #define KLOG_DEBUG 0
9 #define KLOG_INFO 1
10 #define KLOG_WARN 2
11 #define KLOG_ERROR 3
12 #define KLOG_FATAL 4
13
14 #define KMSG_LVLSTART '\x1b'
15 #define KMSG_LOGLEVEL(c) ((c) - '0')
16
17 #define KDEBUG "\x1b" stringify__(KLOG_DEBUG)
18 #define KINFO "\x1b" stringify__(KLOG_INFO)
19 #define KWARN "\x1b" stringify__(KLOG_WARN)
20 #define KERROR "\x1b" stringify__(KLOG_ERROR)
21 #define KFATAL "\x1b" stringify__(KLOG_FATAL)
22
23 #define LOG_MODULE(module)                                                     \
24     static void kprintf(const char* fmt, ...)                                  \
25     {                                                                          \
26         va_list args;                                                          \
27         va_start(args, fmt);                                                   \
28         kprintf_m(module, fmt, args);                                          \
29         va_end(args);                                                          \
30     }
31
32 #define printk(fmt, ...) kprintf_v(__FILE__, fmt, ##__VA_ARGS__)
33
34 #define DEBUG(fmt, ...) kprintf(KDEBUG fmt, ##__VA_ARGS__)
35 #define INFO(fmt, ...) kprintf(KINFO fmt, ##__VA_ARGS__)
36 #define WARN(fmt, ...) kprintf(KWARN fmt, ##__VA_ARGS__)
37 #define ERROR(fmt, ...) kprintf(KERROR fmt, ##__VA_ARGS__)
38 #define FATAL(fmt, ...)                                                        \
39     ({                                                                         \
40         kprintf(KFATAL fmt, ##__VA_ARGS__);                                    \
41         fail(fmt);                                                             \
42     })
43
44 void
45 kprintf_m(const char* component, const char* fmt, va_list args);
46
47 void
48 kprintf_v(const char* component, const char* fmt, ...);
49 #endif /* __LUNAIX_SYSLOG_H */