2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
module type LOG = sig
|
|
|
|
|
|
|
|
val debug: ('a, Format.formatter, unit, unit) format4 -> 'a
|
|
|
|
val log_info: ('a, Format.formatter, unit, unit) format4 -> 'a
|
|
|
|
val log_notice: ('a, Format.formatter, unit, unit) format4 -> 'a
|
|
|
|
val warn: ('a, Format.formatter, unit, unit) format4 -> 'a
|
|
|
|
val log_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
2017-11-08 19:02:19 +04:00
|
|
|
val fatal_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
val lwt_debug: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
|
|
|
val lwt_log_info: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
|
|
|
val lwt_log_notice: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
|
|
|
val lwt_warn: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
|
|
|
val lwt_log_error: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
2018-01-22 18:25:48 +04:00
|
|
|
val lwt_fatal_error: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
let log_f
|
2018-02-08 13:51:01 +04:00
|
|
|
?exn ?(section = Lwt_log_core.Section.main) ?location ?logger ~level format =
|
|
|
|
if level < Lwt_log_core.Section.level section then
|
2016-09-08 21:13:10 +04:00
|
|
|
Format.ikfprintf (fun _ -> Lwt.return_unit) Format.std_formatter format
|
|
|
|
else
|
|
|
|
Format.kasprintf
|
2018-02-08 13:51:01 +04:00
|
|
|
(fun msg -> Lwt_log_core.log ?exn ~section ?location ?logger ~level msg)
|
2016-09-08 21:13:10 +04:00
|
|
|
format
|
|
|
|
|
|
|
|
let ign_log_f
|
2018-02-08 13:51:01 +04:00
|
|
|
?exn ?(section = Lwt_log_core.Section.main) ?location ?logger ~level format =
|
|
|
|
if level < Lwt_log_core.Section.level section then
|
2016-09-08 21:13:10 +04:00
|
|
|
Format.ikfprintf (fun _ -> ()) Format.std_formatter format
|
|
|
|
else
|
|
|
|
Format.kasprintf
|
2018-02-08 13:51:01 +04:00
|
|
|
(fun msg -> Lwt_log_core.ign_log ?exn ~section ?location ?logger ~level msg)
|
2016-09-08 21:13:10 +04:00
|
|
|
format
|
|
|
|
|
2017-01-30 22:10:16 +04:00
|
|
|
let sections = ref []
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
module Make(S : sig val name: string end) : LOG = struct
|
|
|
|
|
2017-01-30 22:10:16 +04:00
|
|
|
let () = sections := S.name :: !sections
|
2018-02-08 13:51:01 +04:00
|
|
|
let section = Lwt_log_core.Section.make S.name
|
|
|
|
|
|
|
|
let debug fmt = ign_log_f ~section ~level:Lwt_log_core.Debug fmt
|
|
|
|
let log_info fmt = ign_log_f ~section ~level:Lwt_log_core.Info fmt
|
|
|
|
let log_notice fmt = ign_log_f ~section ~level:Lwt_log_core.Notice fmt
|
|
|
|
let warn fmt = ign_log_f ~section ~level:Lwt_log_core.Warning fmt
|
|
|
|
let log_error fmt = ign_log_f ~section ~level:Lwt_log_core.Error fmt
|
|
|
|
let fatal_error fmt = ign_log_f ~section ~level:Lwt_log_core.Fatal fmt
|
|
|
|
|
|
|
|
let lwt_debug fmt = log_f ~section ~level:Lwt_log_core.Debug fmt
|
|
|
|
let lwt_log_info fmt = log_f ~section ~level:Lwt_log_core.Info fmt
|
|
|
|
let lwt_log_notice fmt = log_f ~section ~level:Lwt_log_core.Notice fmt
|
|
|
|
let lwt_warn fmt = log_f ~section ~level:Lwt_log_core.Warning fmt
|
|
|
|
let lwt_log_error fmt = log_f ~section ~level:Lwt_log_core.Error fmt
|
|
|
|
let lwt_fatal_error fmt = log_f ~section ~level:Lwt_log_core.Fatal fmt
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module Core = Make(struct let name = "core" end)
|
|
|
|
|
2017-01-23 14:09:36 +04:00
|
|
|
type level = Lwt_log_core.level =
|
|
|
|
| Debug
|
2017-11-13 19:34:00 +04:00
|
|
|
(** Debugging message. They can be automatically removed by the
|
|
|
|
syntax extension. *)
|
2017-01-23 14:09:36 +04:00
|
|
|
| Info
|
2017-11-13 19:34:00 +04:00
|
|
|
(** Informational message. Suitable to be displayed when the
|
|
|
|
program is in verbose mode. *)
|
2017-01-23 14:09:36 +04:00
|
|
|
| Notice
|
2017-11-13 19:34:00 +04:00
|
|
|
(** Same as {!Info}, but is displayed by default. *)
|
2017-01-23 14:09:36 +04:00
|
|
|
| Warning
|
2017-11-13 19:34:00 +04:00
|
|
|
(** Something strange happend *)
|
2017-01-23 14:09:36 +04:00
|
|
|
| Error
|
2017-11-13 19:34:00 +04:00
|
|
|
(** An error message, which should not means the end of the
|
|
|
|
program. *)
|
2017-01-23 14:09:36 +04:00
|
|
|
| Fatal
|
|
|
|
|
2018-02-08 13:51:01 +04:00
|
|
|
type template = Lwt_log_core.template
|
|
|
|
let default_template = "$(date) - $(section): $(message)"
|