package riot

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

Install

dune-project
 Dependency

Authors

Maintainers

Sources

riot-0.0.3.tbz
sha256=6201ce27997ec1c4b4509782c6be2fa2bf102b804b11dcbf9ebdb49a123c19c3
sha512=ad70a67601a892700e461efe57484d109b1d08e30d15464ad8611e71dd568c934d3f948afd645e096e4f97ad1935aaeaf5d9b6d9d59c52a82eeb5c4995421646

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 = false; 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.