Files
frigg/lib/js_log/js_log.odin
T
2026-07-27 14:36:37 +01:00

39 lines
1.1 KiB
Odin

package js_log
import "core:log"
import "core:mem"
foreign import "js_log"
@(default_calling_convention="contextless")
foreign js_log {
// you can pass values to the JS side too.
trace :: proc(str: string) ---
debug :: proc(str: string) ---
info :: proc(str: string) ---
warn :: proc(str: string) ---
error :: proc(str: string) ---
}
// Beware that .FATAL is logged as .Error as it is not supported by this interface
// Unknown log levels will be logged by calling 'console.trace'
js_console_logger_proc :: proc(data: rawptr, level: log.Level, text: string, options: log.Options, location := #caller_location) {
switch level {
case .Debug: debug(text)
case .Info: info(text)
case .Warning: warn(text)
case .Error: error(text)
case .Fatal: error(text)
case: trace(text)
}
}
create_js_console_logger :: proc(options := log.Default_Console_Logger_Opts) -> log.Logger {
return log.Logger{
lowest_level = .Debug,
procedure = js_console_logger_proc,
options = options,
data = nil
}
}