package togglelog

All checked builds pass
  1. Overview
  2. Docs
A ppx for compile-time-optional logging

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.1.tar.gz
md5=486b6910109750a354fef184ad72fa95
sha512=cc8eebf787bf83b8e590bd098b31dc2250bdd5b2cae9512f3871e7ba298967e66485a947a1af431941ea9e8a55d708cae1f1da0c8880038089846993575f7ea0

Description

Added to opam-repository:

README

togglelog - an OCaml PPX extension for zero-cost debug logging

This was an experiment and my first PPX driver. Further development is currently unlikely.

This is a PPX extension for OCaml that allows you to add logging to your code which is completely removed at compile time in release builds. It also provides some primitive filtering ability when logging is compiled into the programs.

Example

let () = [%toggle_log "Hello, world!"];
         [%toggle_log "SPECIFIER" (some_potentially_expensive_function ())]

By default, the above code will be translated to (something equivalent to) the following:

let () = (); ()

The PPX rewriter has an --enable flag which can be used to enable logging. When enabled, the above code will be translated to (approximately) the following:

let () =
Printf.printf "[LOG - example.ml:1:9] %s\n" "Hello, world!";
Printf.printf "[LOG (SPECIFIER) - %s\n" (some_potentially_expensive_function ())

You can see the exact code generated in the tests.

This lets you add logging to your code without worrying about the performance impact in release builds.

Usage

Dune

To use togglelog in your Dune project, add the following to your dune file:

(exectuable
  (name myexe)
  (preprocess (pps togglelog))
  (instrumentation (backend togglelog --enable)))

This sets up togglelog to be used during all builds, but will only enable logging when Dune is invoked with the --instrument-with togglelog flag.

Specifiers

When two arguments are passed to the %toggle_log PPX, the first is a "specifier". This literal string is printed as part of the message, but can also be used to filter the output of the logger.

By default, all log messages are printed. However, if the OCAML_TOGGLELOG environment variable is set to a comma-separated list of specifiers, only messages with matching specifiers will be printed.

Dependencies (3)

  1. ppxlib >= "0.22"
  2. dune >= "3.6"
  3. ocaml >= "4.08.0"

Dev Dependencies (1)

  1. odoc with-doc

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building togglelog with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.1.1 (this version) good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure