package riot

  1. Overview
  2. Docs
An actor-model multi-core scheduler for OCaml 5

Install

Dune Dependency

Authors

Maintainers

Sources

riot-0.0.5.tbz
sha256=01b7b82ccc656b12b7315960d9df17eb4682b8f1af68e9fee33171fee1f9cf88
sha512=d8831d8a75fe43a7e8d16d2c0bb7d27f6d975133e17c5dd89ef7e575039c59d27c1ab74fbadcca81ddfbc0c74d1e46c35baba35ef825b36ac6c4e49d7a41d0c2

doc/src/riot.lib/logger_app.ml.html

Source file logger_app.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
open Runtime
include Logger

module Formatter = struct
  type Message.t += Log of log [@@unboxed]

  let stdout =
    Format.make_formatter (output_substring stdout) (fun () -> flush stdout)

  let rec formatter_loop config =
    match receive () with
    | Log { message; ts; src = sch, pid; level; ns } ->
        let pp_now = Ptime.pp_rfc3339 ~frac_s:5 ~space:true ~tz_offset_s:0 () in

        let ns_str =
          match ns with [] -> "" | _ -> String.concat "." ns ^ "::"
        in

        if config.color_output then
          Format.fprintf stdout "%s" (Level.to_color_string level);
        if config.print_time then Format.fprintf stdout "%a " pp_now ts;
        if config.print_source then
          Format.fprintf stdout "[thread=%a,pid=%a] " Scheduler_uid.pp sch
            Pid.pp pid;
        Format.fprintf stdout "[%s%a] %s\x1b[0m\n%!" ns_str Level.pp level
          message;

        formatter_loop config
    | _ -> formatter_loop config

  let start_link config =
    let pid = spawn_link (fun () -> formatter_loop config) in
    set_on_log (fun log -> send pid (Log log));
    Ok pid

  let child_spec config = Supervisor.child_spec ~start_link config
end

let name = "Riot.Logger"

let default_opts =
  { print_time = true; print_source = false; color_output = true }

let start () =
  let child_specs = [ Formatter.child_spec default_opts ] in
  let (Ok pid) = Supervisor.start_link ~child_specs () in
  Ok pid
[@@warning "-8"]
OCaml

Innovation. Community. Security.