diff options
author | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:11:21 +0200 |
---|---|---|
committer | Lassi Pulkkinen <lassi@pulk.fi> | 2024-10-31 03:51:35 +0200 |
commit | ae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch) | |
tree | 5f462459ae4b47d22114eed717d1382d08cf4dfe /tracer+android.ha |
Diffstat (limited to 'tracer+android.ha')
-rw-r--r-- | tracer+android.ha | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tracer+android.ha b/tracer+android.ha new file mode 100644 index 0000000..2e69527 --- /dev/null +++ b/tracer+android.ha @@ -0,0 +1,43 @@ +use fmt; +use io; +use memio; +use strings; +use trace; + +type Tracer = struct { + trace::tracer, +}; + +fn newtracer() Tracer = + Tracer { + log = &tracer_log, + }; + +fn tracer_log( + tr: *trace::tracer, + ctx: nullable *trace::context, + lvl: trace::level, + fmt: str, + fields: fmt::field... +) void = { + // XXX: ideally there would be a statically allocated buffer for + // reasonably short messages and allocation would only happen for + // messages longer than that. ideally ideally there would be locking so + // we wouldn't need to allocate at all. + const buf = memio::dynamic_from(alloc([], 256)); + defer io::close(&buf)!; + + let ctx_ = ctx; + for (true) match (ctx_) { + case let ctx__: *trace::context => + fmt::fprintf(&buf, ctx__.fmt, ctx__.fields...)!; + io::write(&buf, [0x3a, 0x20])!; // ": " + ctx_ = ctx__.next; + case null => break; + }; + + fmt::fprintfln(&buf, fmt, fields...)!; + + const prio = 6 - lvl: int; + androlog(prio, memio::string(&buf)!); +}; |