1 #include <lunaix/fs/twifs.h>
2 #include <lunaix/fs/twimap.h>
3 #include <lunaix/syscall.h>
4 #include <lunaix/syslog.h>
6 #include <lunaix/lxconsole.h>
8 #include <klibc/strfmt.h>
10 #include "kp_records.h"
13 #define MAX_BUFSZ_HLF 256
14 #define MAX_KPENT_NUM 1024
16 static char tmp_buf[MAX_BUFSZ];
18 static struct kp_records kprecs = {
19 .kp_ents = { .ents = { .next = &kprecs.kp_ents.ents,
20 .prev = &kprecs.kp_ents.ents } },
21 .max_recs = MAX_KPENT_NUM,
22 .kp_ent_wp = &kprecs.kp_ents.ents
26 shift_level(const char* str, int* level)
28 if (str[0] == KMSG_LVLSTART) {
29 *level = KMSG_LOGLEVEL(str[1]);
39 kprintf_ml(const char* component, int level, const char* fmt, va_list args)
41 char* buf = &tmp_buf[MAX_BUFSZ_HLF];
42 ksnprintf(buf, MAX_BUFSZ_HLF, "%s: %s", component, fmt);
44 size_t sz = ksnprintfv(tmp_buf, buf, MAX_BUFSZ_HLF, args);
45 kprec_put(&kprecs, level, tmp_buf, sz);
47 // FIXME temp measure, get some output
48 console_write_str(tmp_buf);
49 console_write_char('\n');
53 kprintf_m(const char* component, const char* fmt, va_list args)
56 fmt = shift_level(fmt, &level);
58 kprintf_ml(component, level, fmt, args);
62 __twimap_kprintf_read(struct twimap* map)
64 struct kp_records* kprecs = twimap_data(map, struct kp_records*);
67 XXX we can foreach all records in a single twimap read call,
68 as records is monotonic increasing by design.
70 struct kp_entry *pos, *n;
71 llist_for_each(pos, n, kprecs->kp_ent_wp, ents)
73 time_t s = pos->time / 1000;
74 time_t ms = pos->time % 1000;
75 twimap_printf(map, "[%05d.%03d] %s\n", s, ms, pos->content);
80 kprintf_mapping_init()
82 twimap_entry_simple(NULL, "kmsg", &kprecs, __twimap_kprintf_read);
84 EXPORT_TWIFS_PLUGIN(kprintf, kprintf_mapping_init);
86 __DEFINE_LXSYSCALL3(void, syslog, int, level, const char*, fmt, va_list, args)
88 kprintf_ml("syslog", level, fmt, args);