Skip to content

Commit

Permalink
verbose_entry_ids prefixes values with entry id tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Mar 3, 2024
1 parent f69ceb4 commit 452b0d3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [1.4.0] -- current

### Added

- A setting `verbose_entry_ids` that prefixes logged values with entry id tags.

### Changed

- Fixes [#32](https://github.com/lukstafi/ppx_minidebug/issues/32): optionally output time spans instead of clock times.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ the runtime, and look for the header with the log's entry id. Example from the t
└─{orphaned from #1} |}]
```
`~verbose_entry_ids:true` tags all logs with entry ids, it shouldn't be needed in regular use.
### Reducing the size of generated logs
Summary of possibilities:
Expand Down
2 changes: 2 additions & 0 deletions index.mld
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ the runtime, and look for the header with the log's entry id. Example from the t
└─{orphaned from #1} |}]
]}

[~verbose_entry_ids:true] tags all logs with entry ids, it shouldn't be needed in regular use.

{2 Reducing the size of generated logs}

Summary of possibilities:
Expand Down
52 changes: 38 additions & 14 deletions minidebug_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ module type Shared_config = sig
val elapsed_times : elapsed_times
val location_format : location_format
val print_entry_ids : bool
val verbose_entry_ids : bool
val global_prefix : string
val split_files_after : int option
end

let elapsed_default = Not_reported

let shared_config ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_default)
?(location_format = Beg_pos) ?(print_entry_ids = false) ?(global_prefix = "")
?split_files_after ?(for_append = true) filename : (module Shared_config) =
?(location_format = Beg_pos) ?(print_entry_ids = false) ?(verbose_entry_ids = false)
?(global_prefix = "") ?split_files_after ?(for_append = true) filename :
(module Shared_config) =
let module Result = struct
let () =
match split_files_after with
Expand Down Expand Up @@ -119,6 +121,7 @@ let shared_config ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_default)
let elapsed_times = elapsed_times
let location_format = location_format
let print_entry_ids = print_entry_ids
let verbose_entry_ids = verbose_entry_ids
let global_prefix = if global_prefix = "" then "" else global_prefix ^ " "
let split_files_after = split_files_after
end in
Expand Down Expand Up @@ -180,6 +183,9 @@ let time_span ~none ~some elapsed elapsed_times =
let opt_entry_id ~print_entry_ids ~entry_id =
if print_entry_ids && entry_id >= 0 then "{#" ^ Int.to_string entry_id ^ "} " else ""

let opt_verbose_entry_id ~verbose_entry_ids ~entry_id =
if verbose_entry_ids && entry_id >= 0 then "{#" ^ Int.to_string entry_id ^ "} " else ""

module Flushing (Log_to : Shared_config) : Debug_runtime = struct
open Log_to

Expand Down Expand Up @@ -240,6 +246,7 @@ module Flushing (Log_to : Shared_config) : Debug_runtime = struct
Printf.fprintf !debug_ch "%s%s%s%s begin %!" (indent ()) global_prefix
(opt_entry_id ~print_entry_ids ~entry_id)
message;
let message = opt_verbose_entry_id ~verbose_entry_ids ~entry_id ^ message in
(match Log_to.location_format with
| No_location -> ()
| File_only -> Printf.fprintf !debug_ch "\"%s\":%!" fname
Expand Down Expand Up @@ -591,6 +598,20 @@ module PrintBox (Log_to : Shared_config) = struct
snapshot ())

let stack_next ~entry_id ~is_result ~prefixed (hl, b) =
let opt_eid = opt_verbose_entry_id ~verbose_entry_ids ~entry_id in
let rec eid b =
match B.view b with
| B.Empty -> B.line opt_eid
| B.Text { l = []; style } -> B.line_with_style style opt_eid
| B.Text { l = s :: more; style } -> B.lines_with_style style ((opt_eid ^ s) :: more)
| B.Frame b -> B.frame @@ eid b
| B.Pad ({ x; y }, b) -> B.pad' ~col:x ~lines:y @@ eid b
| B.Align { h; v; inner } -> B.align ~h ~v @@ eid inner
| B.Grid _ -> B.hlist ~bars:false [ B.line opt_eid; b ]
| B.Tree (indent, h, b) -> B.tree ~indent (eid h) @@ Array.to_list b
| B.Link { uri; inner } -> B.link ~uri @@ eid inner
in
let b = if opt_eid = "" then b else eid b in
match config.log_level with
| Nothing -> ()
| Prefixed _ when not prefixed -> ()
Expand Down Expand Up @@ -859,11 +880,12 @@ module PrintBox (Log_to : Shared_config) = struct
end

let debug_file ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_default)
?(location_format = Beg_pos) ?(print_entry_ids = false) ?(global_prefix = "")
?split_files_after ?highlight_terms ?exclude_on_path ?(prune_upto = 0)
?(truncate_children = 0) ?(for_append = false) ?(boxify_sexp_from_size = 50)
?(max_inline_sexp_length = 80) ?backend ?hyperlink ?(values_first_mode = false)
?(log_level = Everything) ?snapshot_every_sec filename : (module PrintBox_runtime) =
?(location_format = Beg_pos) ?(print_entry_ids = false) ?(verbose_entry_ids = false)
?(global_prefix = "") ?split_files_after ?highlight_terms ?exclude_on_path
?(prune_upto = 0) ?(truncate_children = 0) ?(for_append = false)
?(boxify_sexp_from_size = 50) ?(max_inline_sexp_length = 80) ?backend ?hyperlink
?(values_first_mode = false) ?(log_level = Everything) ?snapshot_every_sec filename :
(module PrintBox_runtime) =
let filename =
match backend with
| None | Some (`Markdown _) -> filename ^ ".md"
Expand All @@ -873,7 +895,7 @@ let debug_file ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_default)
let module Debug =
PrintBox
((val shared_config ~time_tagged ~elapsed_times ~location_format ~print_entry_ids
~global_prefix ~for_append ?split_files_after filename)) in
~verbose_entry_ids ~global_prefix ~for_append ?split_files_after filename)) in
Debug.config.backend <- Option.value backend ~default:(`Markdown default_md_config);
Debug.config.boxify_sexp_from_size <- boxify_sexp_from_size;
Debug.config.max_inline_sexp_length <- max_inline_sexp_length;
Expand All @@ -889,10 +911,10 @@ let debug_file ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_default)
(module Debug)

let debug ?debug_ch ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_default)
?(location_format = Beg_pos) ?(print_entry_ids = false) ?(global_prefix = "")
?highlight_terms ?exclude_on_path ?(prune_upto = 0) ?(truncate_children = 0)
?(values_first_mode = false) ?(log_level = Everything) ?snapshot_every_sec () :
(module PrintBox_runtime) =
?(location_format = Beg_pos) ?(print_entry_ids = false) ?(verbose_entry_ids = false)
?(global_prefix = "") ?highlight_terms ?exclude_on_path ?(prune_upto = 0)
?(truncate_children = 0) ?(values_first_mode = false) ?(log_level = Everything)
?snapshot_every_sec () : (module PrintBox_runtime) =
let module Debug = PrintBox (struct
let refresh_ch () = false
let ch = match debug_ch with None -> stdout | Some ch -> ch
Expand All @@ -915,6 +937,7 @@ let debug ?debug_ch ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_defaul
let elapsed_times = elapsed_times
let location_format = location_format
let print_entry_ids = print_entry_ids
let verbose_entry_ids = verbose_entry_ids
let global_prefix = if global_prefix = "" then "" else global_prefix ^ " "
let split_files_after = None
end) in
Expand All @@ -929,8 +952,8 @@ let debug ?debug_ch ?(time_tagged = Not_tagged) ?(elapsed_times = elapsed_defaul

let debug_flushing ?debug_ch:d_ch ?filename ?(time_tagged = Not_tagged)
?(elapsed_times = elapsed_default) ?(location_format = Beg_pos)
?(print_entry_ids = false) ?(global_prefix = "") ?split_files_after
?(for_append = false) () : (module Debug_runtime) =
?(print_entry_ids = false) ?(verbose_entry_ids = false) ?(global_prefix = "")
?split_files_after ?(for_append = false) () : (module Debug_runtime) =
let log_to =
match (filename, d_ch) with
| None, _ ->
Expand All @@ -956,6 +979,7 @@ let debug_flushing ?debug_ch:d_ch ?filename ?(time_tagged = Not_tagged)
let elapsed_times = elapsed_times
let location_format = location_format
let print_entry_ids = print_entry_ids
let verbose_entry_ids = verbose_entry_ids
let global_prefix = if global_prefix = "" then "" else global_prefix ^ " "
let split_files_after = split_files_after
end : Shared_config)
Expand Down
8 changes: 7 additions & 1 deletion minidebug_runtime.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module type Shared_config = sig
val elapsed_times : elapsed_times
val location_format : location_format
val print_entry_ids : bool
val verbose_entry_ids : bool
val global_prefix : string
val split_files_after : int option
end
Expand All @@ -48,6 +49,7 @@ val shared_config :
?elapsed_times:elapsed_times ->
?location_format:location_format ->
?print_entry_ids:bool ->
?verbose_entry_ids:bool ->
?global_prefix:string ->
?split_files_after:int ->
?for_append:bool ->
Expand All @@ -68,7 +70,8 @@ val shared_config :
defaults to [Not_reported].
If [print_entry_ids] is true, the [entry_id] identifiers are printed on log headers with the syntax
[{#ID}]; by default they are omitted.
[{#ID}]; by default they are omitted. If [verbose_entry_ids] is true, the [entry_id] identifiers
are also printed on logged values.
If [global_prefix] is given, the log header messages (and the log closing messages for the flushing
backend) are prefixed with it. *)
Expand Down Expand Up @@ -192,6 +195,7 @@ val debug_file :
?elapsed_times:elapsed_times ->
?location_format:location_format ->
?print_entry_ids:bool ->
?verbose_entry_ids:bool ->
?global_prefix:string ->
?split_files_after:int ->
?highlight_terms:Re.t ->
Expand Down Expand Up @@ -223,6 +227,7 @@ val debug :
?elapsed_times:elapsed_times ->
?location_format:location_format ->
?print_entry_ids:bool ->
?verbose_entry_ids:bool ->
?global_prefix:string ->
?highlight_terms:Re.t ->
?exclude_on_path:Re.t ->
Expand All @@ -246,6 +251,7 @@ val debug_flushing :
?elapsed_times:elapsed_times ->
?location_format:location_format ->
?print_entry_ids:bool ->
?verbose_entry_ids:bool ->
?global_prefix:string ->
?split_files_after:int ->
?for_append:bool ->
Expand Down

0 comments on commit 452b0d3

Please sign in to comment.