Skip to content

refactor: Consolidate LOG_DEBUG macro definitions to eliminate duplication #294

Description

@kcenon

Summary

Consolidate multiple LOG_DEBUG macro definitions into a single implementation to eliminate preprocessor duplication.

Background (Why)

  • LOG_DEBUG macro is defined 4 times with minor variations
  • Different definitions for debug/release builds and logger name variants
  • Increases maintenance complexity and risk of inconsistency
  • Preprocessor duplication is hard to detect and maintain

Scope (What)

Current State (Duplicated Definitions)

File: include/kcenon/common/logging/log_macros.h

Line Definition Variant
57 LOG_DEBUG(msg) With default logger
111 LOG_DEBUG(logger, msg) With named logger
270-273 LOG_DEBUG(msg) Release build (no-op)

```cpp
// Line 57: Debug build, default logger
#define LOG_DEBUG(msg)
LOG_IMPL(kcenon::common::interfaces::log_level::debug, msg)

// Line 111: Debug build, named logger
#define LOG_DEBUG(logger_name, msg)
LOG_IMPL_NAMED(logger_name, kcenon::common::interfaces::log_level::debug, msg)

// Lines 270-273: Release build
#ifdef NDEBUG
#define LOG_DEBUG(msg) ((void)0)
#endif
```

Proposed State

```cpp
// Single variadic macro handling all cases
#ifdef NDEBUG
#define LOG_DEBUG(...) ((void)0)
#else
#define LOG_DEBUG(...) LOG_DEBUG_IMPL(VA_ARGS)

// Use variadic dispatch
#define LOG_DEBUG_IMPL(...) \
    LOG_DEBUG_DISPATCH(LOG_DEBUG_NARG(__VA_ARGS__), __VA_ARGS__)

#define LOG_DEBUG_1(msg) \
    LOG_IMPL(kcenon::common::interfaces::log_level::debug, msg)

#define LOG_DEBUG_2(logger, msg) \
    LOG_IMPL_NAMED(logger, kcenon::common::interfaces::log_level::debug, msg)

#endif
```

Impact Analysis (Where)

  • File: include/kcenon/common/logging/log_macros.h
  • Lines affected: 57, 111, 270-273
  • Duplicated code: ~15 lines
  • Risk: Low - macro consolidation with same behavior

Implementation Plan (How)

  1. Create variadic macro dispatch mechanism
  2. Consolidate LOG_DEBUG definitions
  3. Apply same pattern to LOG_TRACE, LOG_INFO, LOG_WARNING, LOG_ERROR
  4. Verify all existing usages compile correctly
  5. Run full test suite
  6. Update macro documentation

Acceptance Criteria

  • Single LOG_DEBUG definition (plus release variant)
  • All log macros support both 1-arg and 2-arg forms
  • No functionality changes
  • All tests passing
  • Documentation updated

Labels

  • refactor
  • code-quality
  • duplication

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions