make post-init Xlog.logs work

This commit is contained in:
xenia 2024-04-23 03:43:55 -04:00
parent 501da880cb
commit 48f761d210
3 changed files with 44 additions and 9 deletions

View File

@ -46,3 +46,23 @@ else
Xlog.init_pretty_writer stdout
~min_level:Xlog.DEBUG
```
## 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
```

View File

@ -12,7 +12,7 @@ type logger = {
let rec root_logger = {
namespace = "";
pnamespace = [];
min_level = 0;
min_level = Int.max_int;
child = root_logger;
sibling = root_logger;
writers = None;
@ -31,10 +31,10 @@ let make_logger parent_logger ns =
let rec logger = {
namespace = String.concat "." (List.rev pnamespace);
pnamespace = pnamespace;
min_level = Int.max_int;
min_level = parent_logger.min_level;
child = logger;
sibling = parent_logger.child;
writers = None;
writers = parent_logger.writers;
} in
parent_logger.child <- logger;
logger

View File

@ -1,13 +1,28 @@
[%%xlog_import]
let () =
Xlog.init_pretty_writer stdout ~min_level:Xlog.DEBUG
module Submodule = struct
[%%xlog_import]
let do_stuff () =
[%xlog warn "meow"]
end
let () =
[%xlog info "meow meow %s %d" "test string" 1337]
let () =
try
Xlog.init_pretty_writer stdout ~min_level:Xlog.DEBUG;
[%xlog info "meow meow %s %d" "test string" 1337];
begin try
failwith "meow2"
with
| e -> [%xlog exn e "oop's %d" 42069]
end;
[%xlog info "awa"];
Submodule.do_stuff ()
module Submodule2 = struct
[%%xlog_import]
let do_stuff () =
[%xlog warn "meow"]
end
let () = Submodule2.do_stuff ()