package migra

  1. Overview
  2. Docs
A database migration tool and library for OCaml supporting PostgreSQL, MariaDB/MySQL, and SQLite

Install

dune-project
 Dependency

Authors

Maintainers

Sources

migra-1.0.1.tbz
sha256=daaaab416e580e5b8dc9f0a74482e142cef6d77b248d995d320f6f882d3a9e35
sha512=8f60494b9ee6ac2e7e69a16eefce69d1e8c22e831fe28f600a42200e3086e2f4d15331323ad1848f7165e1c8ff30fe320445185b7e988325588293a66937966a

doc/src/migra.engine/logging.ml.html

Source file logging.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
(** Logging configuration for Migra. *)

(** Setup logging with timestamps.

    This is called automatically when the library loads. You typically don't
    need to call this manually. *)
let setup () =
  (* Check if the default nop reporter is still active *)
  let current_reporter = Logs.reporter () in
  if current_reporter == Logs.nop_reporter then
    (* No reporter set up yet, install ours *)
  begin
    Fmt_tty.setup_std_outputs ();
    let pp_header ppf (l, h) =
      let timestamp = Unix.gettimeofday () in
      let tm = Unix.localtime timestamp in
      let frac = int_of_float ((timestamp -. floor timestamp) *. 1000.) in
      let header = match h with Some h -> h | None -> "migra" in
      Fmt.pf ppf "%02d.%02d.%02d %02d:%02d:%02d.%03d %15s %a "
        (tm.tm_year mod 100) (tm.tm_mon + 1) tm.tm_mday tm.tm_hour tm.tm_min
        tm.tm_sec frac header Logs.pp_level l
    in
    let reporter = Logs_fmt.reporter ~pp_header () in
    Logs.set_reporter reporter;
    Logs.set_level (Some Logs.Info);
    ()
  end
  else
    (* Reporter already exists, respect the existing configuration *)
    ()

(** Set the minimum log level. *)
let set_level level = Logs.set_level (Some level)

(* Automatically initialize logging when the library is loaded *)
let () = setup ()