nspkg / engine / log.v
27 lines · 22 sloc · 681 bytes · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1// typed streaming diagnostics preserve the severity selected by each caller.
2module engine
3
4pub enum LogLevel {
5 error = 1
6 warning = 2
7 debug = 4
8 function = 8
9}
10
11pub type LogCallback = fn (voidptr, LogLevel, string)
12
13pub fn (mut handle Handle) set_log_callback(callback LogCallback, context voidptr) ! {
14 handle.check()!
15 handle.log_callback = callback
16 handle.log_context = context
17}
18
19fn (handle &Handle) has_log_callback() bool {
20 return handle != unsafe { nil } && voidptr(handle.log_callback) != unsafe { nil }
21}
22
23fn (handle &Handle) log(level LogLevel, message string) {
24 if handle.has_log_callback() {
25 handle.log_callback(handle.log_context, level, message)
26 }
27}
28