-
-
Save anmonteiro/3b3fd4810dc6481eb662b1e4675a5e36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module type FILE = sig | |
val __FILE__ : string | |
end | |
module Setup (File : FILE) = struct | |
let src = Logs.Src.create File.__FILE__ | |
module Logs = (val Logs.src_log src : Logs.LOG) | |
end | |
let file f = | |
let module File = struct | |
let __FILE__ = f | |
end | |
in | |
(module File : FILE) | |
let setup_logging ?style_renderer level = | |
let pp_header src ppf (l, h) = | |
let src_segment = | |
if Logs.Src.equal src Logs.default then | |
match Array.length Sys.argv with | |
| 0 -> | |
Filename.basename Sys.executable_name | |
| _n -> | |
Filename.basename Sys.argv.(0) | |
else | |
Logs.Src.name src | |
in | |
Format.fprintf | |
ppf | |
"[%a] %a [%s] " | |
Time.pp_hum | |
(Time.now ()) | |
Logs_fmt.pp_header | |
(l, h) | |
src_segment | |
in | |
let format_reporter = | |
let report src = | |
let { Logs.report } = Logs_fmt.reporter ~pp_header:(pp_header src) () in | |
report src | |
in | |
{ Logs.report } | |
in | |
Fmt_tty.setup_std_outputs ?style_renderer (); | |
Logs.set_level level; | |
Logs.set_reporter format_reporter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: