{"id":18621347,"url":"https://github.com/ethz-asl/lpp","last_synced_at":"2025-06-15T06:35:03.211Z","repository":{"id":64829540,"uuid":"526595139","full_name":"ethz-asl/lpp","owner":"ethz-asl","description":"Header only logging library to standardize ros and glog output at compile time.","archived":false,"fork":false,"pushed_at":"2025-04-10T17:21:20.000Z","size":246,"stargazers_count":34,"open_issues_count":5,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T18:51:41.076Z","etag":null,"topics":["cpp","header-only","logging","ros"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ethz-asl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2022-08-19T12:17:10.000Z","updated_at":"2025-03-14T07:24:23.000Z","dependencies_parsed_at":"2024-01-11T21:51:08.879Z","dependency_job_id":"42458afe-68c4-4e64-80b2-51b2f46a52b6","html_url":"https://github.com/ethz-asl/lpp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethz-asl%2Flpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethz-asl%2Flpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethz-asl%2Flpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethz-asl%2Flpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethz-asl","download_url":"https://codeload.github.com/ethz-asl/lpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248329614,"owners_count":21085568,"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","header-only","logging","ros"],"created_at":"2024-11-07T04:11:05.743Z","updated_at":"2025-04-11T02:31:42.994Z","avatar_url":"https://github.com/ethz-asl.png","language":"C++","readme":"# Log++ Logging framework\n[![lpp](https://github.com/ethz-asl/lpp/actions/workflows/cpp_ubuntu20_04.yml/badge.svg)](https://github.com/ethz-asl/lpp/actions/workflows/cpp_ubuntu20_04.yml)\n\n[Latest Code Coverage Report](https://ethz-asl.github.io/lpp/coverage.html) (master branch)\n\n![](docs/Log++.svg)\n***\n\n## Features\n\n- Framework to standardize ros and glog output at compile time.\n- Uses ros/glog's native log calls depending on selected mode.\n- Customize log output\n- All log calls are thread-safe.\n- Lightweight with performance in mind\n- Header only\n- GCC 8 or later required\n- Recommended to use with C++17/C++20, but also works with C++11/C++14.\n\n## Example\n\n`src/demo.cpp`\n```c++\n#include \u003clog++.h\u003e\n\nint main(int argc, char **argv) {\n  LOG_INIT(argv[0]);\n  int foo = 5;\n  \n  LOG(I, \"Foo: \" \u003c\u003c foo);           //Log++ syntax\n  ROS_INFO_STREAM(\"Foo: \" \u003c\u003c foo);  //ROS syntax\n  LOG(INFO) \u003c\u003c \"Foo: \" \u003c\u003c foo;      //Glog syntax\n  return 0;\n}\n```\n### Output with different flags\n\n- MODE_DEFAULT:\n\n```shell\nINFO  Foo: 5\n[ INFO] [1664445448.151401926]: Foo: 5\nI0929 11:57:28.151427 1360708 main.cpp:8] Foo: 5\n```\n\n- MODE_LPP:\n\n```shell\nINFO  Foo: 5\nINFO  Foo: 5\nINFO  Foo: 5\n```\n\n- MODE_GLOG:\n\n```shell\nI0929 11:57:50.238454 1360823 main.cpp:6] Foo: 5\nI0929 11:57:50.238514 1360823 main.cpp:7] Foo: 5\nI0929 11:57:50.238536 1360823 main.cpp:8] Foo: 5\n```\n\n- MODE_ROSLOG:\n\n```shell\n[ INFO] [1664445486.584182057]: Foo: 5\n[ INFO] [1664445486.584212352]: Foo: 5\n[ INFO] [1664445486.584240476]: Foo: 5\n```\n\n## Installation\n\n### Option 1: Copy the header\n1. Copy the header file `include/log++.h` to your project.\n\n2. Add the following line to `CMakeLists.txt` to select the desired mode for...\n\n- a project:\n\n```cmake\n# Valid modes are: MODE_LPP MODE_GLOG MODE_ROSLOG MODE_DEFAULT\n# Use add_definitions(-DMODE_LPP) if cmake version \u003c= 3.11\n\nadd_compile_definitions(MODE_LPP)\n```\n\n- a specific executable or library:\n\n```cmake\ntarget_compile_definitions(my_executable PRIVATE MODE_LPP) \n```\n\n### Option 2: Add Log++ as a submodule\n1. Add Log++ as a submodule with following command:\n```shell\n$ git submodule add git@github.com:ethz-asl/lpp.git\n```\n\n2. Add following lines in `CMakeLists.txt`\n\n```cmake\nadd_subdirectory(my_submodule_dir/lpp)\nadd_executable(my_executable main.cpp)\ntarget_link_libraries(my_executable lpp)\n```\n\n3. To update Log++ to the latest commit, execute the following commands:\n\nFrom submodule directory\n```shell\n$ git pull origin master\n```\n\nFrom parent directory\n```shell\n$ git add path/to/submodule_dir\n```\n\n\n### Option 3: Build as catkin package\n1. Clone the package into the catkin workspace\n\n```shell\n$ git clone git@github.com:ethz-asl/lpp.git\n```\n\n2. Build package\n```shell\n$ catkin build lpp\n```\n\n# Usage\n\n## Modes\n\n- **MODE_LPP** Log++ Logging output.\n- **MODE_GLOG:** Google Logging output. Calls abort() if it logs a fatal error.\n- **MODE_ROSLOG:** ROS Logging output.\n- **MODE_DEFAULT:** Disables Logging standardization. Messages are logged according to their framework.\n- **MODE_NOLOG:** Disables Logging completely. Useful for unittests or in some cases for release builds.\n\n## How severity levels should be used\n\n- **Debug:** Everything too verbose during normal execution and can be ignored.\n- **Info:** Everything that could be of interest during a normal execution, but could also be ignored.\n- **Warning:** Things that may need attention, but are probably not dangerous.\n- **Error:** Things that need attention and probably are dangerous if not handled.\n- **Fatal:** Everything that should stop execution immediately.\n\n\u003e **Note for glog:**\n\u003e\n\u003e - When using with **MODE_ROSLOG** or **MODE_LPP**, the macros DLOG(severity) and VLOG() will get converted\n\u003e to debug severity.\n\u003e\n\u003e - When using with **MODE_GLOG**, the Log++ and Roslog debug macros LOG(D) and ROS_DEBUG() will get converted\n\u003e to DLOG(INFO).\n\u003e\n\u003e - Fatal log messages call abort(). (glog only)\n\n## Log++ Syntax\n\nLog++ provides its own logging functions, if you want to use Log++ as the base logging framework\n\n### Default logging\n\n```c++\nint foo = 1;\nint bar = 3;\nLOG(I, \"Values: \" \u003c\u003c foo \" \" \u003c\u003c bar);\n```\n\n### Conditional logging\n\n```c++\nint foo = 1;\nint bar = 3;\nLOG(I, foo != bar, \"Values: \" \u003c\u003c foo \u003c\u003c \" \" \u003c\u003c bar)\n```\n\n### Occasional logging\n\n```c++\nint foo = 1;\nint bar = 3;\n\nfor (int i = 0; i \u003c 50; i++) {\n  LOG_EVERY(I, 20, \"Values: \" \u003c\u003c foo \u003c\u003c \" \" \u003c\u003c bar) // Log every 20 calls.\n}\n```\n\n### Logging first N occurrences\n\n```c++\nint foo = 1;\nint bar = 3;\n\nfor (int i = 0; i \u003c 10; i++) {\n  LOG_FIRST(I, 5, \"Values: \" \u003c\u003c foo \u003c\u003c \" \" \u003c\u003c bar) //Log first 5 calls.\n}\n```\n\n### Log output customization\nLog++ also allows you to customize the log output with a callback function when using\nMODE_LPP:\n\n```c++\nvoid logCallback(BaseSeverity severity, const std::string\u0026 str) {\n  std::cout \u003c\u003c str \u003c\u003c std::endl;\n}\n\nint main(int argc, char **argv) {\n  LOG_INIT(argv[0], logCallback);\n  ...\n}\n```\n\n## Overview of logging methods\n\n| Method                         | Log++                | Glog                                 | ROS                         | \n|--------------------------------|----------------------|--------------------------------------|-----------------------------|\n| Default logging                | LOG(I, str)          | LOG(INFO) \u003c\u003c str                     | ROS_INFO(str)               |\n| Conditional logging            | LOG(I, cond, str)    | LOG_IF(INFO, cond) \u003c\u003c str            | ROS_INFO_COND(cond, str)    |\n| Occasional logging             | LOG_EVERY(I, n, str) | LOG_EVERY_N(INFO, n) \u003c\u003c str          | -                           |\n| Conditional occasional logging | -                    | LOG_IF_EVERY_N(INFO, cond, n) \u003c\u003c str | -                           |\n| Timed logging                  | LOG_TIMED(I, t, str) | LOG_EVERY_T(INFO, t) \u003c\u003c str          | ROS_INFO_THROTTLE(t, str)   |\n| First N occurrences            | LOG_FIRST(I, n, str) | LOG_FIRST_N(INFO, n) \u003c\u003c str          | ROS_INFO_ONCE(str) (only 1) |\n| Log to std::vector\\\u003cstring\u003e    | -                    | LOG_STRING(INFO, \u0026vec) \u003c\u003c str        | -                           |\n\n## The following features are currently not supported (Feel free to contribute)\n- Implement ROS_INFO_NAMED() etc.\n- ROS2 support\n\n# Contributions\nThe following information should be considered when contributing to Log++.\n\n## Build Unittests\nUnittests can be built by setting the `LPP_BUILD_TESTS` flag.\nIf building with catkin, the tests can be built with the following command:\n\n```shell\n$ catkin build lpp -DLPP_BUILD_TESTS=1\n```\n\n## Unittests\n- All modes (default, glog, lpp, roslog, nolog) have a separate test suite. All tests should run with each mode.\n- Test all severity levels (Debug, Info, Warning, Error, Fatal)\n- Test if the functionality of a logging function works, not only the logging format (Default, Conditional, Occasional, Timed, First N occurrences)\n- Tests must run in debug mode in order to test debug log output\n\nNaming Convention:\n\n```c++\nTEST(\u003cmode\u003e_\u003cLoggingMethod\u003e, \u003cmode\u003e_syntax_severity_\u003cseverity\u003e) {\n  //Test logic\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethz-asl%2Flpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethz-asl%2Flpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethz-asl%2Flpp/lists"}