{"id":18257922,"url":"https://github.com/linkdd/logfmtxx","last_synced_at":"2025-04-04T18:31:26.219Z","repository":{"id":231433057,"uuid":"781758859","full_name":"linkdd/logfmtxx","owner":"linkdd","description":"Header only C++23 structured logging library using logfmt","archived":false,"fork":false,"pushed_at":"2025-04-03T21:40:34.000Z","size":109,"stargazers_count":71,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-03T22:30:34.104Z","etag":null,"topics":["cpp","cpp23","logfmt","logging","logging-library","structured-logging"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linkdd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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},"funding":{"github":["linkdd"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2024-04-04T01:24:13.000Z","updated_at":"2025-04-03T21:39:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"38975d7d-cf4e-48ef-bbb5-1b916733dcd8","html_url":"https://github.com/linkdd/logfmtxx","commit_stats":null,"previous_names":["linkdd/logfmtxx"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Flogfmtxx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Flogfmtxx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Flogfmtxx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Flogfmtxx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdd","download_url":"https://codeload.github.com/linkdd/logfmtxx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247229381,"owners_count":20905040,"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":["cpp","cpp23","logfmt","logging","logging-library","structured-logging"],"created_at":"2024-11-05T10:28:09.247Z","updated_at":"2025-04-04T18:31:26.214Z","avatar_url":"https://github.com/linkdd.png","language":"C++","readme":"# logfmtxx\n\nHeader-only C++23 structured logging library using the\n[logfmt](https://brandur.org/logfmt) format.\n\n## Installation\n\nJust copy the `include/logfmtxx.hpp` in your project.\n\nOr with [Shipp](https://github.com/linkdd/shipp), add it to your dependencies:\n\n```json\n{\n  \"name\": \"myproject\",\n  \"version\": \"0.1.0\",\n  \"dependencies\": [\n    {\n      \"name\": \"logfmtxx\",\n      \"url\": \"https://github.com/linkdd/logfmtxx.git\",\n      \"version\": \"v0.4.1\"\n    }\n  ]\n}\n```\n\n## Usage\n\nFirst, include the relevant headers:\n\n```cpp\n#include \u003ciostream\u003e // if you wish to print logs with std::cout or std::cerr\n#include \u003clogfmtxx.hpp\u003e\n```\n\nThen create a logger:\n\n```cpp\nauto logger = logfmtxx::logger{\n  [](const std::string\u0026 message) {\n    std::cout \u003c\u003c message \u003c\u003c std::endl;\n  }\n};\n```\n\nOr with a functor to avoid allocations:\n\n```cpp\nstruct printer {\n  void operator()(const std::string\u0026 message) {\n    std::cout \u003c\u003c message \u003c\u003c std::endl;\n  }\n};\nauto logger = logfmtxx::logger{printer{}};\n```\n\nOr with global fields:\n\n```cpp\nauto logger = logfmtxx::logger{\n  [](const std::string\u0026 message) {\n    std::cout \u003c\u003c message \u003c\u003c std::endl;\n  },\n  logfmtxx::field{\"foo\", 42},\n  logfmtxx::field{\"bar\", 3.14}\n};\n```\n\nThen, call the `log()` method:\n\n```cpp\nlogger.log(logfmtxx::level::info, \"hello world\");\n// or\nlogger.info(\"hello world\");\n```\n\nThe result should be:\n\n```\ntime=2001-01-01T00:00:00Z level=info message=\"hello world\" foo=42 bar=3.14000\n```\n\nYou can add extra fields as well:\n\n```cpp\nlogger.log(\n  logfmtxx::level::error,\n  \"internal server error\",\n  logfmtxx::field{\"http.method\", \"GET\"},\n  logfmtxx::field{\"http.path\", \"/\"},\n  logfmtxx::field{\"http.status\", 500}\n);\n```\n\nThe result should be:\n\n```\ntime=2001-01-01T00:00:00Z level=error message=\"internal server error\" foo=42 bar=3.14000 http.method=\"GET\" http.path=\"/\" http.status=500\n```\n\nIf your type implements `as_string()`, it can be used with a field:\n\n```cpp\nstruct foo {\n  std::string as_string() const {\n    return \"i am foo\";\n  }\n};\n\nlogger.log(logfmtxx::level::info, \"example\", logfmtxx::field{\"foo\", foo{}});\n```\n\n## Benchmark\n\n**CPU:** 13th Gen Intel(R) Core(TM) i7-13700K 3.40 GHz\n\n**Results:**\n\n|               ns/op |                op/s |    err% |     total | benchmark\n|--------------------:|--------------------:|--------:|----------:|:----------\n|            7,326.07 |          136,498.88 |    1.1% |      0.09 | `logger.info with context (fast)`\n|            7,169.35 |          139,482.70 |    0.7% |      0.09 | `logger.info without context (fast)`\n|            9,707.22 |          103,016.06 |    1.3% |      0.03 | `logger.info with context (slow)`\n|            9,448.67 |          105,835.01 |    0.7% |      0.03 | `logger.info without context (slow)`\n\n## License\n\nThis software is released under the terms of the\n[BSD 0-clause License](./LICENSE.txt).\n","funding_links":["https://github.com/sponsors/linkdd"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Flogfmtxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdd%2Flogfmtxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Flogfmtxx/lists"}