Module Brr.Console
Browser console.
See Console. Take a few minutes to understand this.
val get : unit -> Brr.Console.tget () is the console object on which the functions below act. Initially this is G.console.
val set : Brr.Console.t -> unitset o sets the console object to o.
clear () clears the console.
Log functions
The type for log messages.
type 'a msgr = 'a -> Brr.Console.msgThe type for functions turning values of type 'a into log messages.
val msg : 'a Brr.Console.msgrmsg v is [v].
type log = Brr.Console.msg -> unitThe type for log functions.
Log messages rebind OCaml's list syntax. This allows to write heterogeneous logging statements concisely.
let () = Console.(log [1; 2.; true; Jv.true'; str "🐫"; G.navigator])The console logs JavaScript values. For OCaml values this means that their js_of_ocaml representation is logged; see the FFI manual for details. Most OCaml values behind Brr types are however direct JavaScript values and logging them as is will be valuable. For other values you can use the str function which invokes the JavaScript toString method on the value. It works on OCaml strings and is mostly equivalent and shorter than calling Jstr.v before logging them.
In the JavaScript console API, if the first argument is a JavaScript string it can have formatting specifications. Just remember this should be a JavaScript string, so wrap OCaml literals by str or Jstr.v:
let () = Console.(log [str "This is:\n%o\n the navigator"; G.navigator])val str : 'a -> Jstr.tstr v is the result of invoking the JavaScript toString method on the representation of v. If v is Jv.null and Jv.undefined a string representing them is directly returned.
Result logging
val log_result :
?ok:'a Brr.Console.msgr ->
?error:'b Brr.Console.msgr ->
('a, 'b) Stdlib.result ->
('a, 'b) Stdlib.resultlog_result ~ok ~error r is r but logs r using log and ok to format Ok v and error and error for Error e. ok defaults to [v] and error to [str e].
val log_if_error :
?l:Brr.Console.log ->
?error_msg:'b Brr.Console.msgr ->
use:'a ->
('a, 'b) Stdlib.result ->
'alog_if_error ~l ~error_msg ~use r is v if r is Ok v and use if r is Error e. In this case e is logged with l (defaults to error) and error_msg (defaults to str e).
val log_if_error' :
?l:Brr.Console.log ->
?error_msg:'b Brr.Console.msgr ->
use:'a ->
('a, 'b) Stdlib.result ->
('a, 'b) Stdlib.resultlog_if_error' is log_if_error wrapped by Result.ok.
Levelled logging
val log : Brr.Console.loglog m logs m with no specific level.
val trace : Brr.Console.logtrace m logs m with no specific level but with a stack trace, like error and warn do.
val error : Brr.Console.logerror m logs m with level error.
val warn : Brr.Console.logwarn m logs m with level warn.
val info : Brr.Console.logwarn m logs m with level info.
val debug : Brr.Console.logdebug m logs m with level debug.
Asserting and dumping
val assert' : bool -> Brr.Console.logassert' c m asserts c and logs m with a stack trace iff c is false.
val table : ?cols:Jstr.t list -> 'a -> unittable v outputs v as tabular data. If cols is specified only the specified properties are printed.
Grouping
val group : ?closed:bool -> Brr.Console.loggroup ~closed msg logs msg and pushes a new inline group in the console. This indents messages until group_end is called. If closed is true (defaults to false) the group's content is hidden behind a disclosure button.
group_end () pops the last inline group.
Counting
val count : Jstr.t -> unitcount label logs label with the number of times count label was called.
Timing
val time_log : Jstr.t -> Brr.Console.logtime_log label msg reports the timer value of label with msg appended to the report.
Profiling
val time_stamp : Jstr.t -> unittime_stamp label adds a marker labeled by label in the waterfall view.
val to_jv : Brr.Console.t -> Jv.jvval of_jv : Jv.jv -> Brr.Console.t