{"id":17062587,"url":"https://github.com/wardbrian/togglelog","last_synced_at":"2025-07-27T06:37:29.815Z","repository":{"id":149897832,"uuid":"621469630","full_name":"WardBrian/togglelog","owner":"WardBrian","description":"A PPX writer which lets you compile out logging statements in release builds","archived":false,"fork":false,"pushed_at":"2024-02-28T18:59:50.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T18:13:32.149Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WardBrian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-30T18:18:29.000Z","updated_at":"2023-04-06T01:03:04.000Z","dependencies_parsed_at":"2024-10-14T11:01:43.212Z","dependency_job_id":null,"html_url":"https://github.com/WardBrian/togglelog","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Ftogglelog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Ftogglelog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Ftogglelog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WardBrian%2Ftogglelog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WardBrian","download_url":"https://codeload.github.com/WardBrian/togglelog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610338,"owners_count":21132920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T10:50:18.013Z","updated_at":"2025-04-12T18:13:36.953Z","avatar_url":"https://github.com/WardBrian.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# togglelog - an OCaml PPX extension for zero-cost debug logging\n\n**This was an experiment and my first PPX driver. Further development is currently unlikely.**\n\nThis is a [PPX extension](https://ocaml.org/docs/metaprogramming) for OCaml that allows you to add logging to your code which is completely removed at compile time in release builds.\nIt also provides some primitive filtering ability when logging is compiled into the programs.\n\n## Example\n\n```ocaml\nlet () = [%toggle_log \"Hello, world!\"];\n         [%toggle_log \"SPECIFIER\" (some_potentially_expensive_function ())]\n```\n\nBy default, the above code will be translated to (something equivalent to) the following:\n```ocaml\nlet () = (); ()\n```\n\nThe PPX rewriter has an `--enable` flag which can be used to enable logging. When enabled,\nthe above code will be translated to (approximately) the following:\n```ocaml\nlet () =\nPrintf.printf \"[LOG - example.ml:1:9] %s\\n\" \"Hello, world!\";\nPrintf.printf \"[LOG (SPECIFIER) - %s\\n\" (some_potentially_expensive_function ())\n```\n\nYou can see the exact code generated in the [tests](./test/output.t/run.t).\n\nThis lets you add logging to your code without worrying about the performance impact in release builds.\n\n## Usage\n\n### Dune\n\nTo use `togglelog` in your Dune project, add the following to your `dune` file:\n```scheme\n(exectuable\n  (name myexe)\n  (preprocess (pps togglelog))\n  (instrumentation (backend togglelog --enable)))\n```\n\nThis sets up `togglelog` to be used during all builds, but will only enable logging when Dune is invoked\nwith the `--instrument-with togglelog` flag.\n\n\n## Specifiers\n\nWhen two arguments are passed to the `%toggle_log` PPX, the first is a \"specifier\".\nThis literal string is printed as part of the message, but can also\nbe used to filter the output of the logger.\n\nBy default, all log messages are printed. However, if the `OCAML_TOGGLELOG`\nenvironment variable is set to a comma-separated list of specifiers, only\nmessages with matching specifiers will be printed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwardbrian%2Ftogglelog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwardbrian%2Ftogglelog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwardbrian%2Ftogglelog/lists"}