package ocaml-systemd

  1. Overview
  2. Docs
OCaml module for native access to the systemd facilities

Install

Dune Dependency

Authors

Maintainers

Sources

1.3.tar.gz
sha256=717acee7f71bc04ff3bb53c0af1231bd5c8112d4f2c1830562d5087cf1d4b152
sha512=9e69281cee9e26ee96bf33dc7624c6866021b2f227214c0e1376c101c77b245ab52c1a044c0b7be87d7a20beea81bb69fb33df450c7311b8fec3a608e650d7c2

doc/src/systemd/journald.ml.html

Source file journald.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
open Printexc

module Priority = struct
  type t =
    | EMERG | ALERT | CRIT | ERR | WARNING | NOTICE | INFO | DEBUG
  external to_int : t -> int = "caml_journal_level_to_int"
end

external caml_journal_send : string list -> unit = "caml_journal_send"

let journal_send l = List.map (function (k,v) -> k ^ "=" ^ v) l |> caml_journal_send

let default_entries p s = ("PRIORITY", ((Priority.to_int p) |> string_of_int))::("MESSAGE", s)::[]

let journal_send_message p s = default_entries p s |> journal_send

(* assuming get_location is called from function in backtrace 3 slots above   *)
let get_location () = match (get_callstack 3 |> backtrace_slots) with
  | Some s -> Array.get s 2 |> Slot.location
  | None -> None

let journal_send_loc l = match get_location () with
  | Some {filename; line_number; _} -> journal_send (("CODE_FILE", filename)::("CODE_LINE", string_of_int line_number)::l)
  | None -> journal_send l

let journal_send_message_loc p s = match get_location () with
  | Some {filename; line_number; _} -> journal_send (("CODE_FILE", filename)::("CODE_LINE", string_of_int line_number)::(default_entries p s))
  | None -> journal_send_message p s
OCaml

Innovation. Community. Security.