logging library for cats written in ocaml
Go to file
xenia 0eb9e97ac6 add missing ppxlib dependency 2024-04-23 13:59:09 -04:00
lib make post-init Xlog.logs work 2024-04-23 03:43:55 -04:00
ppx bikeshed ppx 2024-04-23 03:33:56 -04:00
test make post-init Xlog.logs work 2024-04-23 03:43:55 -04:00
.gitignore initial commit 2024-04-22 22:41:07 -04:00
README.md make post-init Xlog.logs work 2024-04-23 03:43:55 -04:00
dune-project add missing ppxlib dependency 2024-04-23 13:59:09 -04:00
package.nix add missing ppxlib dependency 2024-04-23 13:59:09 -04:00
xlog.opam add missing ppxlib dependency 2024-04-23 13:59:09 -04:00

README.md

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

include (val Xlog.logs __FUNCTION__)

(* basic usage *)
let () =
  info (fun m -> m "meow meow meow")

(* 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")

module Submodule = struct
  include (val Xlog.logs __FUNCTION__)

  (* ... *)
end

(* in the main module *)
Xlog.init_pretty_writer stdout
  ~min_level:Xlog.DEBUG
  (* other options *)

(* if running as a daemon *)
if Xlog.should_upgrade_to_journald () then
  Xlog.init_journald_writer ()
    ~min_level:Xlog.DEBUG
else
  Xlog.init_pretty_writer stdout
    ~min_level:Xlog.DEBUG

usage with ppx

[%%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