Skip to content

[Helper] Messaging: add msg_*_once macros to display a message only once per component instance#6164

Open
fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:loggging_msg_once
Open

[Helper] Messaging: add msg_*_once macros to display a message only once per component instance#6164
fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:loggging_msg_once

Conversation

@fredroy

@fredroy fredroy commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

A lot of code throw message in often-called functions such as draw() or update() or in loops.
and often, a boilerplate code like

static bool first = true;
if (first)
{
 msg_*() << "blabla"
 first = false;
}

is used, like for example in #6152 , when you want to warn the user once in the draw method, but dont want to spam.

So I asked Claude to implement a msg_*_once function to display only once per component (this part of code is quite... special)

Introduces msg_info_once / msg_warning_once / msg_error_once / msg_fatal_once /  msg_deprecated_once / 
msg_advice_once, which emit their message only the first time  a given emitter instance reaches the call site (tracked per-
instance, per-thread via a  lock-free thread_local set). Useful to avoid spamming repeated warnings from update loops. 
Includes a unit test (onceMessagePerInstance) verifying the per-instance behavior.

The only small flaw is that the OnceTracker is thread-local so If emitted from different threads it will be displayed more than once. But the other alternative was a std::mutex (his first version) so it could introduce uncessary locks IMO

I flagged experimental because the Messaging part is a bit complex...


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy fredroy added this to the v26.12 milestone Jun 25, 2026
@fredroy fredroy added pr: enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request pr: experimental Demonstrate an experimental feature pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Jun 25, 2026
@fredroy fredroy force-pushed the loggging_msg_once branch from 3de5a26 to fd13f5f Compare June 26, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: enhancement About a possible enhancement pr: experimental Demonstrate an experimental feature pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant