{"id":25090784,"url":"https://github.com/san7o/oak","last_synced_at":"2025-04-01T19:34:14.504Z","repository":{"id":256271174,"uuid":"854788317","full_name":"San7o/oak","owner":"San7o","description":"A feature-rich, thread-safe C++23 logger with no external dependencies. Log to file, unix and network sockets, serialization, configure logging dynamically using config files, use colors for different log levels and more features.","archived":false,"fork":false,"pushed_at":"2024-09-16T11:19:02.000Z","size":1084,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T12:43:00.900Z","etag":null,"topics":["logging","modern-cpp"],"latest_commit_sha":null,"homepage":"https://san7o.github.io/brenta-engine-documentation/oak/v1.0/","language":"C++","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/San7o.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2024-09-09T19:24:14.000Z","updated_at":"2025-02-06T20:49:57.000Z","dependencies_parsed_at":"2025-02-07T12:35:31.306Z","dependency_job_id":"42544132-c454-433e-93ae-c84438f89fbf","html_url":"https://github.com/San7o/oak","commit_stats":null,"previous_names":["san7o/oak"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/San7o%2Foak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/San7o%2Foak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/San7o%2Foak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/San7o%2Foak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/San7o","download_url":"https://codeload.github.com/San7o/oak/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246701144,"owners_count":20820004,"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":["logging","modern-cpp"],"created_at":"2025-02-07T12:32:03.330Z","updated_at":"2025-04-01T19:34:14.483Z","avatar_url":"https://github.com/San7o.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"![oak-banner](./docs/oak_banner.jpeg)\n\nOak is a lightweight and robust logging library for C++23, designed to\nsimplify logging in modern C++ applications.\n\nBuilt with modern C++ practices, Oak leverages advanced language\nfeatures to offer high performance and flexibility. Key features include:\n- **Thread-Safety**: Oak ensures safe logging in multi-threaded environments,\n                 preventing data races and synchronization issues.\n- **Minimal Overhead**: Optimized for performance, Oak introduces minimal\n                 runtime overhead, ensuring it doesn't compromise the speed\n                 of your application.\n- **Simplicity and Ease of Use**: Oak's API is intuitive, allowing you to integrate\n                 it seamlessly into your project without a steep learning curve.\n- **Customization**: Oak offers a range of customization options, allowing you to\n                 tailor the logging experience to your specific requirements.\n\nThis code was originally forked from the logger of [Brenta Engine](https://github.com/San7o/Brenta-Engine)\nin order to develop it independently from the engine.\n\n## Features\n\n- **multiple logging levels**\n\n- **log to file**\n\n- **log to unix sockets**\n\n- **log to net sockets**\n\n- **log metadata**\n\n- **settings file**\n\n- **json serialization**\n\n- **thread safety**\n\n- **log buffering**\n\n- **async logging**\n\n# Usage\nTo include oak in your project, simply [include/oak/oak.hpp](./include/oak/oak.hpp) and [src/oak.cpp](./src/oak.cpp)\nin your import directory and source directory respectively. That's it!\n\nTo build oak as a library, you can use the compile options `OAK_BUILD_SHARED` and `OAK_BUID_STATIC`:\n```bash\ncmake -Bbuild -DOAK_BUILD_STATIC=ON\n```\n\n## Quick Tour\n\nTo learn about all the functionalities, please visit the [html documentation](https://san7o.github.io/brenta-engine-documentation/oak/v1.0/). Here is presented a quick guide to\nshowcase the library's api.\n\n### The writer\nThe logger uses a writer to read the message queue and correctly\nwrites the output in the specified location, allowing buffering.\n```c++\noak::init_writer();\n// Do stuff and have fun here\noak::stop_writer();\n```\n\n### How to log\nLog something with the level `info`:\n```c++\noak::info(\"i love {}!\", what);\n```\n```bash\n# output\n[level=info] i love oak!\n```\nOr use macros if you prefer:\n```c++\nOAK_INFO(\"add a {} to this library!\", star);\n```\n\n### Set the Log level\nOnly logs with an higher level will be logged:\n```c++\noak::set_level(oak::level::debug);\n```\n\n### Add metadata\n```c++\noak::set_flags(oak::flags::level, oak::flags::date);\n```\n```bash\n# example output\n[level=info,date=2024-09-11] nice\n```\n\nYou can also serialize the log adding the flag `oak::flags::json`:\n```\n{ \"level\": \"output\", \"date\": \"2024-09-11\", \"time\": \"15:35:20\", \"pid\": 30744, \"tid\": 9992229128130766714, \"message\": \"Hello Mario\" }\n```\n\n### Log to file\n```c++\nauto file = oak::set_file(\"/tmp/my-log\");\nif (!file.has_value())\n    oak::error(\"Error setting file: {}\", file.error());\n```\nThe library uses `std::expected` to handle errors.\n\n### Log to socket\n```c++\n// unix sockets\noak::set_socket(\"/tmp/a-socket\");\n// net socket, defaults to tcp\noak::set_socket(\"127.0.0.1\", 1337);\n// udp net socket\noak::set_socket(\"127.0.0.1\", 5678, protocol_t::udp);\n```\n\n### Settings file\nYou can save the settings in a file with `key=value,...`, like this:\n```\nlevel = debug\nflags = level, date, time, pid, tid\nfile = tests/log_test.txt\n```\nAnd use this settings like so:\n```c++\nauto r = oak::settings_file(\"settings.oak\");\nif (!r.has_value())\n    oak::error(\"Error opening setting file: {}\", r.error());\n```\n\n### Async logging\n```c++\noak::async(oak::level:debug, \"Time travelling\");\n```\n\n# Contributing\nAny new contributor is welcome to this project. Please\nread [CONTRIBUTING](./CONTRIBUTING.md) for intructions\non how to contribute.\n\n## Testing\n\nThe test project uses cmake. To build and run the tests, run:\n```c++\ncmake -Bbuild\ncmake --build build -j 4\n./build/tests\n```\n\n## Fuzzing\n\nThe library supports [fuzztest](https://github.com/google/fuzztest/tree/main) for fuzzing. You\nneed a recent version of clang to run the fuzzing, then you can compile the project in `fuzz/`\nwith cmake using the following commands:\n```bash\nCXX=clang++ cmake -Bbuild -S fuzz -DFUZZTEST_FUZZING_MODE=on\nCXX=clang++ cmake --build build\n./build/fuzz -fuzz=fuzz_log_to_string.test_log_to_string\n```\n\nOr simply run\n```bash\nmake fuzz\n```\nTo run the same commands. Note that it might take some time to build fuzztest the first time.\n\n## Documentation\n\nThe project's documentation uses doxygen, to generate the html documentation locally, please run:\n```bash\ndoxygen doxygen.conf\n```\n\n## Formatting\n\nThe library uses `clang-format` for formatting, the rules\nare saved in [.clang-format](./.clang-format).\n\nTo format the code, run:\n```bash\nmake format\n```\n\n## License\n\nThe library is licensed under [MIT](./LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsan7o%2Foak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsan7o%2Foak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsan7o%2Foak/lists"}