2024-04-23 02:36:13 +00:00
|
|
|
# xlog
|
|
|
|
|
|
|
|
logging library for cats written in ocaml
|
|
|
|
|
|
|
|
original code (most of the code here) from: <https://git.lain.faith/iitalics/talircd>, which is
|
|
|
|
released under LGPL-2.0-or-later. all modifications to the code in this repo are released under the
|
|
|
|
same license
|
|
|
|
|
|
|
|
## usage
|
|
|
|
|
|
|
|
```ocaml
|
|
|
|
include (val Xlog.logs __FUNCTION__)
|
|
|
|
|
2024-04-23 05:39:03 +00:00
|
|
|
(* basic usage *)
|
2024-04-23 02:36:13 +00:00
|
|
|
let () =
|
|
|
|
info (fun m -> m "meow meow meow")
|
|
|
|
|
2024-04-23 05:39:03 +00:00
|
|
|
(* add source location info *)
|
|
|
|
let () =
|
|
|
|
info ~__POS__ ~__FUNCTION__ (fun m -> m "meow meow meow")
|
|
|
|
|
|
|
|
(* log exception *)
|
|
|
|
try
|
|
|
|
fallible_task ()
|
|
|
|
with
|
|
|
|
| e ->
|
|
|
|
exn e (Printexc.get_raw_backtrace ()) ~__POS__ ~__FUNCTION__
|
|
|
|
(fun m -> m "encountered error")
|
|
|
|
|
2024-04-23 02:36:13 +00:00
|
|
|
module Submodule = struct
|
|
|
|
include (val Xlog.logs __FUNCTION__)
|
|
|
|
|
|
|
|
(* ... *)
|
|
|
|
end
|
2024-04-23 05:39:03 +00:00
|
|
|
|
|
|
|
(* in the main module *)
|
|
|
|
Xlog.init_pretty_writer stdout
|
|
|
|
~min_level:Xlog.DEBUG
|
|
|
|
(* other options *)
|
2024-04-23 02:36:13 +00:00
|
|
|
```
|
2024-04-23 07:43:55 +00:00
|
|
|
|
|
|
|
## usage with ppx
|
|
|
|
|
|
|
|
```ocaml
|
|
|
|
[%%xlog_import]
|
|
|
|
|
|
|
|
[%xlog info "log message %d" 1337]
|
|
|
|
|
|
|
|
try
|
|
|
|
fallible_task ()
|
|
|
|
with
|
|
|
|
| e -> [%xlog exn e "oop's"]
|
|
|
|
|
|
|
|
module Submodule = struct
|
|
|
|
[%%xlog_import]
|
|
|
|
|
|
|
|
let do_stuff () =
|
|
|
|
[%xlog warn "meow"]
|
|
|
|
end
|
|
|
|
```
|