package echo

  1. Overview
  2. Docs
A minimal interop OCaml + C logging solution

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.0.5.tar.gz
md5=f21fc179d03f16acc57b6e1d844993fb
sha512=7bd62891dedf1b2d7f39d07ea6b58266bcc62d4ccd667931f8fb51d8767cd3b2238a567adf89b173f9c0f7d246a62893cc237a91b8c60e6899ef53715f0ad376

Description

Echo is a lightweight logging library for OCaml with C lib bindings, allowing both OCaml and C code to emit structured log messages through a unified logging interface.

Tags

logging console

Published: 15 Jul 2025

README

Echo

Echo is a lightweight logging library for OCaml with C lib bindings, allowing both OCaml and C code to emit structured log messages through a unified logging interface.

OCaml and C logging to the terminal

Features

  • C bindings for easy logging integration with your C lib (see C API section below)
  • Supports output to stdout, stderr, and .log files
  • Standard log levels: TRACE, INFO, WARN, ERROR, FATAL
  • Manual flushing of logs

Installation

Echo can be installed with opam:

opam install echo

opam package page: https://opam.ocaml.org/packages/echo

API Overview

OCaml

val set_out : out_type -> unit
val trace : ('a, unit, string, unit) format4 -> 'a
val info : ('a, unit, string, unit) format4 -> 'a
val warn : ('a, unit, string, unit) format4 -> 'a
val error : ('a, unit, string, unit) format4 -> 'a
val fatal : ('a, unit, string, unit) format4 -> 'a
val flush : unit -> unit

C

Don't forget to #include <echo.h>

void echo_trace(const char *fmt, ...);
void echo_info(const char *fmt, ...);
void echo_warn(const char *fmt, ...);
void echo_error(const char *fmt, ...);
void echo_fatal(const char *fmt, ...);

Example Usage

In OCaml

let main () =
  (* Optional: Redirect logs to a file *)
  Echo.set_out (File "debug.log");

  (* Log from OCaml *)
  Echo.trace "Starting analysis of '%s'" "report.csv";
  Echo.info "Processed %d items" 42;
  Echo.warn "Unusual delay: %.2f ms" 123.45;
  Echo.error "Failed to read file '%s'" "data.bin";
  Echo.fatal "Unrecoverable crash in module '%s'" "engine";

  Echo.flush ()

let () = main ()

In C

#include "echo.h"

void dummie_c_fn()
{
    echo_trace("%s", "message");
    echo_info("%s", "message");
    echo_warn("%s", "message");
    echo_error("%s", "message");
    echo_fatal("%s", "message");
}

License

MIT License — free to use, modify, and distribute.

Contributions

Contributions are welcome! Feel free to open issues or submit PRs if you find bugs or have ideas for improvement.

Dependencies (8)

  1. alcotest
  2. ctypes-foreign >= "0.23.0"
  3. ctypes >= "0.20.0"
  4. fmt >= "0.8.10"
  5. stdio
  6. base
  7. ocaml >= "4.14"
  8. dune >= "3.18"

Dev Dependencies (1)

  1. odoc with-doc

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.