Skip to content

Commit 48f36f7

Browse files
committed
Merge pull request #171 from frenetic-lang/log
Update logging to use core/async.111.28.00 logging API
2 parents b0128b7 + 5cea105 commit 48f36f7

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

async/Async_OpenFlow.mli

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ module Log : sig
77

88
include Log.Global_intf
99

10+
val of_lazy
11+
: ?level:[ `Debug | `Info | `Error ]
12+
-> ?time:Time.t
13+
-> ?tags:(string * string) list
14+
-> string Lazy.t
15+
-> unit
16+
1017
val make_filtered_output : (string * string) list ->
1118
Log.Output.t
1219

async/Async_OpenFlow_Log.ml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ let stderr : Log.Output.t =
4646

4747
let log = lazy (Log.create ~level:`Info ~output:[stderr])
4848

49+
let level () = Log.level (Lazy.force log)
4950
let set_level = Log.set_level (Lazy.force log)
5051

5152
let set_output outputs = current_outputs := outputs;
@@ -56,24 +57,33 @@ let add_output outputs =
5657
current_outputs := outputs;
5758
set_output outputs
5859

59-
let raw ?(tags=[]) fmt = Log.raw (Lazy.force log) ~tags fmt
60+
let raw ?time ?(tags=[]) fmt = Log.raw (Lazy.force log) ?time ~tags fmt
6061

61-
let info ?(tags=[]) fmt = Log.info (Lazy.force log) ~tags fmt
62+
let info ?time ?(tags=[]) fmt = Log.info (Lazy.force log) ?time ~tags fmt
6263

63-
let error ?(tags=[]) fmt = Log.error (Lazy.force log) ~tags fmt
64+
let error ?time ?(tags=[]) fmt = Log.error (Lazy.force log) ?time ~tags fmt
6465

65-
let debug ?(tags=[]) fmt = Log.debug (Lazy.force log) ~tags fmt
66+
let debug ?time ?(tags=[]) fmt = Log.debug (Lazy.force log) ?time ~tags fmt
6667

6768
let flushed () =
6869
Log.flushed (Lazy.force log)
6970

70-
let printf ?(tags=[]) ?(level=`Debug) fmt =
71+
let printf ?(level=`Debug) ?time ?(tags=[]) fmt =
7172
Log.printf (Lazy.force log) ~tags ~level fmt
7273

73-
let of_lazy ?(tags=[]) ?(level=`Debug) lazy_str =
74-
Log.of_lazy (Lazy.force log) ~tags ~level lazy_str
74+
let of_lazy ?(level=`Debug) ?time ?(tags=[]) lazy_str =
75+
(* As of core/async.111.25.00, `Log.of_lazy` is no longer part of that
76+
* package's public API. In 111.28.00, the `Log.level` call was added,
77+
* allowing users of the package to implement `of_lazy` without having to
78+
* manage the log level manually.
79+
* *)
80+
if level = Log.level (Lazy.force log) then
81+
Log.printf (Lazy.force log) ~tags ~level "%s" (Lazy.force lazy_str)
7582

76-
let sexp ?(tags=[]) ?(level=`Debug) msg =
77-
Log.sexp (Lazy.force log) ~tags ~level msg
83+
let sexp ?(level=`Debug) ?time ?(tags=[]) msg =
84+
Log.sexp (Lazy.force log) ~tags ~level msg
85+
86+
let string ?(level=`Debug) ?time ?(tags=[]) str =
87+
Log.string (Lazy.force log) ~tags ~level str
7888

7989
let message = Log.message (Lazy.force log)

0 commit comments

Comments
 (0)