Skip to content

Commit 79bd9f9

Browse files
committed
Use Lwt_log message format
This restores Ocsigen's message format, including the date and section name. This adds the log level to the message, which was missing before.
1 parent 39d1528 commit 79bd9f9

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/server/ocsigen_messages.ml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,42 @@ let access_sect = Logs.Src.create "ocsigen:access"
2525
let full_path f = Filename.concat (Ocsigen_config.get_logdir ()) f
2626
let error_log_path () = full_path error_file
2727

28-
let stderr =
29-
let logs_formatter = Format.formatter_of_out_channel stderr in
30-
Logs.format_reporter ~app:logs_formatter ~dst:logs_formatter ()
28+
(* This is the date format inherited from [Lwt_log]. *)
29+
let pp_date ppf =
30+
let time = Unix.gettimeofday () in
31+
let tm = Unix.localtime time in
32+
let month_string =
33+
match tm.Unix.tm_mon with
34+
| 0 -> "Jan"
35+
| 1 -> "Feb"
36+
| 2 -> "Mar"
37+
| 3 -> "Apr"
38+
| 4 -> "May"
39+
| 5 -> "Jun"
40+
| 6 -> "Jul"
41+
| 7 -> "Aug"
42+
| 8 -> "Sep"
43+
| 9 -> "Oct"
44+
| 10 -> "Nov"
45+
| 11 -> "Dec"
46+
| _ -> ""
47+
in
48+
Format.fprintf ppf "%s %2d %02d:%02d:%02d" month_string tm.Unix.tm_mday
49+
tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec
3150

32-
let stdout =
33-
let logs_formatter = Format.formatter_of_out_channel stdout in
34-
Logs.format_reporter ~app:logs_formatter ~dst:logs_formatter ()
51+
let make_reporter out_channel =
52+
let ppf = Format.formatter_of_out_channel out_channel in
53+
let report src level ~over k msgf =
54+
let k _ = over (); k () in
55+
msgf @@ fun ?header ?tags:_ fmt ->
56+
Format.kfprintf k ppf
57+
("%t: %s: %a @[" ^^ fmt ^^ "@]@.")
58+
pp_date (Logs.Src.name src) Logs.pp_header (level, header)
59+
in
60+
{Logs.report}
3561

62+
let stderr = make_reporter stderr
63+
let stdout = make_reporter stdout
3664
let close_loggers = ref []
3765

3866
let open_files () =
@@ -77,8 +105,7 @@ let open_files () =
77105
in
78106
let open_log path =
79107
let channel, close = open_channel path in
80-
let logs_formatter = Format.formatter_of_out_channel channel in
81-
Logs.format_reporter ~app:logs_formatter ~dst:logs_formatter (), close
108+
make_reporter channel, close
82109
in
83110
let acc = open_log access_file in
84111
let war = open_log warning_file in

0 commit comments

Comments
 (0)