Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/server/log.ml
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,22 @@ let sub_log ?level:level_ name =
log ~tags format_and_arguments))
in

let level =
List.find Option.is_some [
Option.map to_logs_level level_;
List.assoc_opt name !custom_log_levels;
Some !level
] in
let source_level =
match level_ with
| Some level ->
let level = to_logs_level level in
custom_log_levels :=
(name, level)::(List.remove_assoc name !custom_log_levels);
Some level
| None ->
List.assoc_opt name !custom_log_levels
in

(* Create the actual Logs source, and then wrap all the interesting
functions. *)
let src = Logs.Src.create name in
let (module Log) = Logs.src_log src in
Logs.Src.set_level src level;
custom_log_levels :=
(name, Option.get level)::(List.remove_assoc name !custom_log_levels);
Logs.Src.set_level src source_level;
sources := (name, src) :: (List.remove_assoc name !sources);

{
Expand Down
24 changes: 24 additions & 0 deletions test/unit/log.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(* This file is part of Dream, released under the MIT license. See LICENSE.md
for details, or visit https://github.com/camlworks/dream.

Copyright 2026 funwithcthulhu *)



let (-:) name f = Alcotest.test_case name `Quick f



let tests = "log", [

"default debug follows initialized level" -: begin fun () ->
let called = ref false in
Dream.initialize_log ~level:`Debug ();
Dream.debug (fun log ->
called := true;
log "debug");
!called
|> Alcotest.(check bool) "called" true
end;

]
1 change: 1 addition & 0 deletions test/unit/unit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ let () =
Alcotest.run "Dream" [
Request.tests;
Headers.tests;
Log.tests;
]
Loading