Hi,I would like to write a logger in OCaml. In C++ it's pretty straightforward with macro expansion that gives correct call site (file & line):$ cat -n cpp-logger.cpp1 #include <iostream>23 #define LOG_START do {\4 std::cerr << __FILE__ << ":" << __LINE__ << ": "5 #define LOG_END std::endl; } while (0)67 int main()8 {9 LOG_START << "Got problem!" << LOG_END;10 return 0;11 }$ ./a.outcpp-logger.cpp:9: Got problem!In OCaml we have __LOC__ and __LOC_OF__:However it's not trivial to get correct call site:$ cat -n yahoo.ml1 print_string "yahoo\n";;23 Printf.printf "__LOC__ = %s\n" __LOC__;;45 let report s =6 let loc, _ = __LOC_OF__ s in7 Printf.printf "LOC of the expression (%s): %s\n" s loc ;;89 report "bad bug" ;;$ ./a.outyahoo__LOC__ = File "yahoo.ml", line 3, characters 31-38LOC of the expression (bad bug): File "yahoo.ml", line 6, characters 28-29I expect line 9 but I get line 6 in OCaml. I would appreciate some help to get this working. Does it involve campl4/5 / ppx?
Thanks.--Kind regards,Viet