Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a sub_log does not respect the initial log level #299

Closed
leflings opened this issue Sep 15, 2023 · 1 comment
Closed

Creating a sub_log does not respect the initial log level #299

leflings opened this issue Sep 15, 2023 · 1 comment

Comments

@leflings
Copy link

Given the folllowing code:

let my_log = Dream.sub_log ~level:`Error "my.log"

let () =
  Dream.run
  @@ Dream.logger
  @@ Dream.router
       [ Dream.get "/" (fun _ -> Dream.html "Welcome to my website")
       ; Dream.get "/echo/:word" (fun req ->
           my_log.warning (fun log -> log ~request:req "echo path");
           Dream.html (Printf.sprintf "Hello, %s" @@ Dream.param req "word"))
       ]
;;

I expect that echo path will not be logged, as it is a warning, and this sub_log is only configured with errors.

However, it is still being logged:

15.09.23 10:00:58.532       dream.log  INFO REQ 1 GET /echo/dream 127.0.0.1:45198 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/51
15.09.23 10:00:58.532          my.log  WARN REQ 1 echo path
15.09.23 10:00:58.532       dream.log  INFO REQ 1 200 in 87 μs

"Manually" setting the log level with the following line:

let () = Dream.set_log_level "my.log" `Error

Makes it behave as expected:

15.09.23 10:03:37.447       dream.log  INFO REQ 1 GET /echo/dream 127.0.0.1:33510 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/51
15.09.23 10:03:37.447       dream.log  INFO REQ 1 200 in 56 μs

I am running OCaml 4.14.1 under WSL2

@aantron aantron closed this as completed in 9c72a39 Nov 6, 2023
@aantron
Copy link
Owner

aantron commented Nov 6, 2023

Thank you! This has been fixed in the linked commit and will be out in the next release.

The whole logging initialization code could probably use a rework, as it was already complex when only trying to integrate with Logs, but it is now even more complex because of Mirage support, and it's difficult to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants