Skip to content

Commit

Permalink
deploy: c365828
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Oct 2, 2023
1 parent 0ec1c48 commit 507827a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions asai/quickstart.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
Logger.run ~emit:Term.display ~fatal:Term.display @@ fun () ->
(* your application code *)</code></pre><h2 id="add-backtraces"><a href="#add-backtraces" class="anchor"></a>Add Backtraces</h2><p>Great messages come with meaningful backtraces. To add backtraces, you will have to &quot;annotate&quot; your code to generate meaningful stack frames. Suppose this is one of the functions whose invocation should be noted in user-facing backtraces:</p><pre class="language-ocaml"><code>let f x y =
(* very important code *)</code></pre><p>Add <a href="Asai/Logger/module-type-S/index.html#val-trace">trace</a> to add a frame to the current backtrace:</p><pre class="language-ocaml"><code>let f x y =
Logger.trace &quot;When calling f...&quot; @@ fun () -&gt;
Logger.trace &quot;When calling f&quot; @@ fun () -&gt;
(* very important code *)</code></pre><p>Similar to <a href="Asai/Logger/module-type-S/index.html#val-emitf">emitf</a>, there is also <a href="Asai/Logger/module-type-S/index.html#val-tracef">tracef</a> which allows you to format messages:</p><pre class="language-ocaml"><code>let f x y =
Logger.tracef &quot;When calling f on %d and %d...&quot; x y @@ fun () -&gt;
Logger.tracef &quot;When calling f on %d and %d&quot; x y @@ fun () -&gt;
(* very important code *)</code></pre><p>Note that, by default, the terminal backend will not show backtraces. You have to enable it as follows in your entry-point module:</p><pre class="language-ocaml"><code>module Term = Asai.Tty.Make (Logger.Code)

let () =
Expand All @@ -46,7 +46,7 @@
{|Unrecognized token &quot;%s&quot;|} String.escaped token
| Grammar.Error -&gt;
Logger.fatal ~loc:(Span.of_lexbuf lexbuf) ParsingError
&quot;Could not parse the program&quot;</code></pre><p>Please take a look at <a href="Asai/Span/index.html"><code>Asai.Span</code></a> to learn all kinds of ways to create a span!</p><p>Note that <code>Logger</code> will remember and reuse the innermost specified location, and thus you do not have to explicitly pass it. For example, in the following code</p><pre class="language-ocaml"><code>Logger.trace ~loc &quot;When checking this code...&quot; @@ fun () -&gt;
&quot;Could not parse the program&quot;</code></pre><p>Please take a look at <a href="Asai/Span/index.html"><code>Asai.Span</code></a> to learn all kinds of ways to create a span!</p><p>Note that <code>Logger</code> will remember and reuse the innermost specified location, and thus you do not have to explicitly pass it. For example, in the following code</p><pre class="language-ocaml"><code>Logger.trace ~loc &quot;When checking this code&quot; @@ fun () -&gt;
(* ... *)
Logger.emit &quot;Wow!&quot; (* using the location [loc] from above *)
(* ... *)</code></pre><p>the inner message <code>&quot;Wow!&quot;</code> will inherit the location <code>loc</code> from the outer <a href="Asai/Logger/module-type-S/index.html#val-trace">trace</a> function call! You can also use <a href="Asai/Logger/module-type-S/index.html#val-merge_loc">merge_loc</a> to &quot;remember&quot; a location for later use, which is helpful when you want to remember a location but not to leave a trace:</p><pre class="language-ocaml"><code>Logger.merge_loc (Some loc) @@ fun () -&gt;
Expand Down

0 comments on commit 507827a

Please sign in to comment.