Files
lux/examples/showcase/custom_logging.lux
2026-02-17 06:52:44 -05:00

37 lines
699 B
Plaintext

effect Log {
fn info(msg: String): Unit
fn debug(msg: String): Unit
}
fn computation(): Int with {Log} = {
Log.info("Starting computation")
let x = 10
Log.debug("x = " + toString(x))
Log.info("Processing")
let result = x * 2
Log.debug("result = " + toString(result))
result
}
handler consoleLogger: Log {
fn info(msg) =
{
Console.print("[INFO] " + msg)
resume(())
}
fn debug(msg) =
{
Console.print("[DEBUG] " + msg)
resume(())
}
}
fn main(): Unit with {Console} = {
let result = run computation() with {
Log = consoleLogger,
}
Console.print("Final: " + toString(result))
}
let output = run main() with {}