487785762d1aa8542adf0a2effcc92dc790798e7
[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 INFO(fmt, ...) kprintf(KINFO fmt, ##__VA_ARGS__)
33 #define WARN(fmt, ...) kprintf(KWARN fmt, ##__VA_ARGS__)
34 #define ERROR(fmt, ...) kprintf(KERROR fmt, ##__VA_ARGS__)
35 #define FATAL(fmt, ...)                                                        \
36     ({                                                                         \
37         kprintf(KFATAL fmt, ##__VA_ARGS__);                                    \
38         spin();                                                                \
39     })
40
41 void
42 kprintf_m(const char* component, const char* fmt, va_list args);
43
44 // TODO need more thought on it
45
46 // struct klog_chunk
47 // {
48 //     void* log_entry;
49 //     size_t max_len;
50 //     size_t len;
51 // };
52
53 // struct klog_chunk*
54 // kprintf_lcstart_m(const char* component, size_t size);
55
56 // void
57 // kprintf_lcappend_m(struct klog_chunk*, const char* fmt, va_list args);
58
59 // void
60 // kprintf_lcdone_m(struct klog_chunk*);
61
62 #endif /* __LUNAIX_SYSLOG_H */