| 1 | // typed streaming diagnostics preserve the severity selected by each caller. |
| 2 | module engine |
| 3 | |
| 4 | pub enum LogLevel { |
| 5 | error = 1 |
| 6 | warning = 2 |
| 7 | debug = 4 |
| 8 | function = 8 |
| 9 | } |
| 10 | |
| 11 | pub type LogCallback = fn (voidptr, LogLevel, string) |
| 12 | |
| 13 | pub 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 | |
| 19 | fn (handle &Handle) has_log_callback() bool { |
| 20 | return handle != unsafe { nil } && voidptr(handle.log_callback) != unsafe { nil } |
| 21 | } |
| 22 | |
| 23 | fn (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 | |