ableos/sysdata/libraries/stn/src/log.hb

36 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-12-19 11:19:57 -06:00
.{string, fmt, memory} := @use("stn")
2024-07-07 08:35:07 -05:00
2024-12-19 11:19:57 -06:00
LogMsg := packed struct {level: LogLevel, string: ^u8, strlen: uint}
2024-09-17 12:08:19 -05:00
2024-12-19 11:19:57 -06:00
LogLevel := enum {
Error,
Warn,
Info,
Debug,
Trace,
}
log := fn(level: LogLevel, message: ^u8): void {
2024-10-25 10:37:38 -05:00
return @eca(3, 1, LogMsg.(level, message, @inline(string.length, message)), @sizeof(LogMsg))
2024-07-07 08:35:07 -05:00
}
2024-12-19 11:19:57 -06:00
error := fn(message: ^u8): void return @inline(log, LogLevel.Error, message)
warn := fn(message: ^u8): void return @inline(log, LogLevel.Warn, message)
info := fn(message: ^u8): void return @inline(log, LogLevel.Info, message)
debug := fn(message: ^u8): void return @inline(log, LogLevel.Debug, message)
trace := fn(message: ^u8): void return @inline(log, LogLevel.Trace, message)
print_buffer := memory.dangling(u8)
print := fn(v: @Any(), opts: fmt.FormatOptions): void {
if @TypeOf(v) == ^u8 {
info(v)
return
}
if print_buffer == memory.dangling(u8) {
print_buffer = memory.request_page(1)
}
len := @inline(fmt.format, v, print_buffer, opts)
@eca(3, 1, LogMsg.(opts.log, print_buffer, len), @sizeof(LogMsg))
memory.set(u8, &0, print_buffer, memory.PAGE_SIZE)
}