Shell: improve logging (prepend the current time)
This commit is contained in:
parent
5eb8d0077a
commit
0b6aa16ca7
@ -30,7 +30,7 @@ let log_f
|
|||||||
Format.ikfprintf (fun _ -> Lwt.return_unit) Format.std_formatter format
|
Format.ikfprintf (fun _ -> Lwt.return_unit) Format.std_formatter format
|
||||||
else
|
else
|
||||||
Format.kasprintf
|
Format.kasprintf
|
||||||
(Lwt_log.log ?exn ~section ?location ?logger ~level)
|
(fun msg -> Lwt_log.log ?exn ~section ?location ?logger ~level msg)
|
||||||
format
|
format
|
||||||
|
|
||||||
let ign_log_f
|
let ign_log_f
|
||||||
@ -39,8 +39,7 @@ let ign_log_f
|
|||||||
Format.ikfprintf (fun _ -> ()) Format.std_formatter format
|
Format.ikfprintf (fun _ -> ()) Format.std_formatter format
|
||||||
else
|
else
|
||||||
Format.kasprintf
|
Format.kasprintf
|
||||||
(fun s ->
|
(fun msg -> Lwt_log.ign_log ?exn ~section ?location ?logger ~level msg)
|
||||||
Lwt_log.ign_log ?exn ~section ?location ?logger ~level s)
|
|
||||||
format
|
format
|
||||||
|
|
||||||
module Make(S : sig val name: string end) : LOG = struct
|
module Make(S : sig val name: string end) : LOG = struct
|
||||||
@ -87,8 +86,10 @@ module Client = struct
|
|||||||
end
|
end
|
||||||
module Webclient = Make(struct let name = "webclient" end)
|
module Webclient = Make(struct let name = "webclient" end)
|
||||||
|
|
||||||
|
let template = "$(date) $(name)[$(pid)]: $(message)"
|
||||||
|
|
||||||
let default_logger () =
|
let default_logger () =
|
||||||
Lwt_log.channel ~close_mode:`Keep ~channel:Lwt_io.stderr ()
|
Lwt_log.channel ~template ~close_mode:`Keep ~channel:Lwt_io.stderr ()
|
||||||
|
|
||||||
type kind =
|
type kind =
|
||||||
| Null
|
| Null
|
||||||
@ -96,6 +97,7 @@ type kind =
|
|||||||
| Stderr
|
| Stderr
|
||||||
| File of string
|
| File of string
|
||||||
| Syslog
|
| Syslog
|
||||||
|
| Manual of Lwt_log.logger
|
||||||
|
|
||||||
let init kind =
|
let init kind =
|
||||||
let logger =
|
let logger =
|
||||||
@ -103,12 +105,13 @@ let init kind =
|
|||||||
| Stderr ->
|
| Stderr ->
|
||||||
default_logger ()
|
default_logger ()
|
||||||
| Stdout ->
|
| Stdout ->
|
||||||
Lwt_log.channel ~close_mode:`Keep ~channel:Lwt_io.stdout ()
|
Lwt_log.channel ~template ~close_mode:`Keep ~channel:Lwt_io.stdout ()
|
||||||
| File file_name ->
|
| File file_name ->
|
||||||
Lwt_main.run (Lwt_log.file ~file_name ())
|
Lwt_main.run (Lwt_log.file ~file_name ~template ())
|
||||||
| Null ->
|
| Null ->
|
||||||
Lwt_log.null
|
Lwt_log.null
|
||||||
| Syslog ->
|
| Syslog ->
|
||||||
Printf.eprintf "Warning: log_kind \"syslog\" not yet implemented.\n%!";
|
Printf.eprintf "Warning: log_kind \"syslog\" not yet implemented.\n%!";
|
||||||
default_logger () in
|
default_logger ()
|
||||||
|
| Manual logger -> logger in
|
||||||
Lwt_log.default := logger
|
Lwt_log.default := logger
|
||||||
|
@ -54,5 +54,6 @@ type kind =
|
|||||||
| Stderr
|
| Stderr
|
||||||
| File of string
|
| File of string
|
||||||
| Syslog
|
| Syslog
|
||||||
|
| Manual of Lwt_log.logger
|
||||||
|
|
||||||
val init: kind -> unit
|
val init: kind -> unit
|
||||||
|
Loading…
Reference in New Issue
Block a user