OCamlPro / niagara-lang

Compiler for the Niagara language
GNU Affero General Public License v3.0
3 stars 6 forks source link

Logs #9

Closed Ninjapouet closed 1 year ago

Ninjapouet commented 1 year ago

Added a configurable log system. Traces must now use the Error module functions like this example:

let foo () =
  Error.info (fun m -> m "all is ok");
  match computation () with
  | code ->
    Error.debug (fun m -> m "computation returned %i" code)
  | exception e ->
    Error.err (fun m -> m "oups (%a)" Fmt.exn e)

It's also possible to construct Rust like error messages by packing sub logs :

let bar () =
   match another_computation () with
   | code -> ()
   | exception e ->
      Error.(err (fun m -> m "something went wrong" ~tags:!![
         primary "there was an error";
         secondary "identified by exception %a" Fmt.exn e;
         hint "program correctly please !"
     ]))

Positions can be added to messages so that such logs can be rendered in a Rust (or whatever) style later.

This PR also gives a true command line system in order to configure logs (colors, GNU style and log selectors for now but more can be added later).