OCaml: Implement log contexts

This commit is contained in:
Juno Takano 2025-05-16 22:53:33 -03:00
commit c6c92c0a32
8 changed files with 29 additions and 25 deletions

View file

@ -1,4 +1,11 @@
let elog (message : string) : unit =
let debug_flag = try Unix.getenv "DEBUG" with Not_found -> "" in
type context = Default | OS | Parsing
if debug_flag <> "" then prerr_endline @@ " [log] " ^ message
let elog ?(context: context option) (message : string) : unit =
let debug_flag = try Unix.getenv "DEBUG" with Not_found -> "" in
let log () = prerr_endline @@ " [log] " ^ message in
match context with
| None | Some Default -> if debug_flag <> "" then log ()
| Some Parsing -> if debug_flag = "parsing" then log ()
| Some OS -> if debug_flag = "os" then log ()