Logging macro conditional on a latch/flipflop
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 77
- Forks
- 135
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 10
Description
A common pattern of logging I have come across in hardware integration is a flipflop kind of pattern:
e.g. Hardware callback reports at 10Hz "BAD" for X seconds, and then reports "GOOD" when hardware state good:
void hardware_callback(const std::string state) {
if (state == "BAD") {
RCLCPP_INFO(get_logger(), "hardware not ready yet");
}
if (state == "GOOD") {
RCLCPP_INFO(get_logger(), "System in good state, ready.");
}
}
Would spam debug msgs:
hardware not ready yet
hardware not ready yet
hardware not ready yet
hardware not ready yet
// and finally system swaps over
System in good state, ready.
System in good state, ready.
System in good state, ready.
System in good state, ready.
System in good state, ready.
// and then back again
hardware not ready yet
hardware not ready yet
hardware not ready yet
hardware not ready yet
hardware not ready yet
Ideally it would be something like:
void hardware_callback(const std::string state) {
if (state == "BAD") {
RCLCPP_INFO_LATCH(get_logger(), hw_state_latch, true, "hardware not ready yet");
}
if (state == "GOOD") {
RCLCPP_INFO_LATCH(get_logger(), hw_state_latch, false, "System in good state, ready.");
}
}
Yielding:
hardware not ready yet
// and finally system swaps over
System in good state, ready.
// and then back again
hardware not ready yet
I'd be willing to write this feature if someone could give me instructions on how it would be implemented in the rcutils framework, and if it would actually be merged.
I am not too sure on how to define the static/global that can be referenced in other functions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named in the issue. Start by locating the rcutils logging macro implementation and its tests, then define done as a latch-controlled macro that emits only on BAD/GOOD state transitions and covers alternating states.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp
- Domain
- observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100