package prr

  1. Overview
  2. Docs

Module Brr.ConsoleSource

Browser console.

See Console. Take a few minutes to understand this.

Sourcetype t

The type for console objects. See G.console for the global console object.

Sourceval get : unit -> t

get () is the console object on which the functions below act. Initially this is G.console.

Sourceval set : t -> unit

set o sets the console object to o.

Sourceval clear : unit -> unit

clear () clears the console.

Log functions

Sourcetype msg =
  1. | [] : msg
  2. | :: : 'a * msg -> msg

The type for log messages.

Sourcetype 'a msgr = 'a -> msg

The type for functions turning values of type 'a into log messages.

Sourceval msg : 'a msgr

msg v is [v].

Sourcetype log = msg -> unit

The 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])
Sourceval str : 'a -> Jstr.t

str 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

Sourceval log_result : ?ok:'a msgr -> ?error:'b msgr -> ('a, 'b) result -> ('a, 'b) result

log_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].

Sourceval log_if_error : ?l:log -> ?error_msg:'b msgr -> use:'a -> ('a, 'b) result -> 'a

log_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).

Sourceval log_if_error' : ?l:log -> ?error_msg:'b msgr -> use:'a -> ('a, 'b) result -> ('a, 'b) result

log_if_error' is log_if_error wrapped by Result.ok.

Levelled logging

Sourceval log : log

log m logs m with no specific level.

Sourceval trace : log

trace m logs m with no specific level but with a stack trace, like error and warn do.

Sourceval error : log

error m logs m with level error.

Sourceval warn : log

warn m logs m with level warn.

Sourceval info : log

warn m logs m with level info.

Sourceval debug : log

debug m logs m with level debug.

Asserting and dumping

Sourceval assert' : bool -> log

assert' c m asserts c and logs m with a stack trace iff c is false.

Sourceval dir : 'a -> unit

dir o logs a listing of the properties of the object othis explains the difference with Console.(log [o]).

Sourceval table : ?cols:Jstr.t list -> 'a -> unit

table v outputs v as tabular data. If cols is specified only the specified properties are printed.

Grouping

Sourceval group : ?closed:bool -> log

group ~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.

Sourceval group_end : unit -> unit

group_end () pops the last inline group.

Counting

Sourceval count : Jstr.t -> unit

count label logs label with the number of times count label was called.

Sourceval count_reset : Jstr.t -> unit

count_reset label resets the counter for count label.

Timing

Sourceval time : Jstr.t -> unit

time label starts a timer named label.

Sourceval time_log : Jstr.t -> log

time_log label msg reports the timer value of label with msg appended to the report.

Sourceval time_end : Jstr.t -> unit

time_end label ends the timer named label.

Profiling

Sourceval profile : Jstr.t -> unit

profile label starts a new profile labelled label.

Sourceval profile_end : Jstr.t -> unit

profile_end label ends ends the new profile labelled label.

Sourceval time_stamp : Jstr.t -> unit

time_stamp label adds a marker labeled by label in the waterfall view.

OCaml

Innovation. Community. Security.