Skip to content

Add slic macros that only log the first time they're called #1685

@kennyweiss

Description

@kennyweiss

A discussion in #1683 prompted the question about adding slic macros that only log/warn the first time they're encountered.

I'd suggest adopted something like the following (based on code that @tomstitt wrote a few years ago):

#define SLIC_INFO_ONCE_IF(cond, msg) \
   do                               \
   {                                \
      static bool once = true;      \
      if (cond)                     \
      {                             \
         if (once)                  \
         {                          \
            SLIC_INFO(msg);          \
            once = false;           \
         }                          \
      }                             \
   } while (false)

#define SLIC_INFO_ONCE(msg) SLIC_INFO_ONCE_IF(true, msg)

#define SLIC_INFO_ONCE_ROOT_IF(cond, msg) \
   do                                    \
   {                                     \
      static bool once = true;           \
      if (cond)                          \
      {                                  \
         if (once)                       \
         {                               \
            SLIC_INFO_ROOT(msg);          \
            once = false;                \
         }                               \
      }                                  \
   } while (false)

#define SLIC_INFO_ONCE_ROOT(msg) SLIC_INFO_ONCE_ROOT_IF(true, msg)

We should also add similar macros for warnings and possibly debug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ReviewedSlicIssues related to Axom's 'slic' componentenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions