Skip to content

feat: dependency-free leveled logging facility#18

Merged
johnaoga merged 2 commits into
mainfrom
ja/feat/logging-system
Jun 18, 2026
Merged

feat: dependency-free leveled logging facility#18
johnaoga merged 2 commits into
mainfrom
ja/feat/logging-system

Conversation

@johnaoga

Copy link
Copy Markdown
Collaborator

Summary

Introduces a small, dependency-free leveled logging facility for CppNCorr and migrates all ad-hoc std::cout / std::cerr / printf output to it. This gives users control over what the engine reports (info / warning / error) and where it goes, with proper verbosity-vs-debug separation.

What's new

  • include/ncorr/log.h + src/log.cpp — a tiny logger (no third-party deps):
    • Five severity levels TRACE / DEBUG / INFO / WARN / ERROR plus OFF.
    • Independent console and log-file thresholds, so a file sink can capture full DEBUG detail while the console stays quiet.
    • Thread-safe (internal mutex), safe to call from the OpenMP parallel DIC regions.
    • Stream-style macros NLOG_TRACE/DEBUG/INFO/WARN/ERROR that short-circuit message construction when the level is disabled — important for the per-frame / per-iteration hot loops in ncorr.cpp.
  • Configuration (the library has no CLI of its own):
    • Env vars NCORR_LOG_LEVEL, NCORR_LOG_FILE, NCORR_LOG_CONSOLE (applied lazily on first use).
    • The existing debug flag lowers the console threshold to DEBUG.
    • Programmatic API: ncorr::log::set_level(), set_file(), Logger::instance().

Migration

All ~164 print sites migrated and categorized: genuine errors → ERROR, WARNING-prefixed → WARN, progress/status → INFO, debug-gated dumps and DEBUG-prefixed diagnostics → DEBUG. The per-frame/per-iteration progress prints now route through guarded macros so they cost nothing when the level is off.

  • src/ncorr.cpp (~142 sites), src/Image2D.cpp (15), include/Array2D.h (2), include/ROI2D.h (1).
  • set_debug(debug) wired at the RGDIC entry points so the existing flag still controls debug verbosity.

Build & verification

  • Wired src/log.cpp / include/ncorr/log.h into CMakeLists.txt.
  • libncorr.a builds clean (only pre-existing template deprecation warnings).
  • Runtime-tested a standalone program linked against libncorr.a: level thresholds, env-var control, and the file sink all behave correctly.
  • Documented in README.md.

🤖 Generated with Claude Code

johnaoga and others added 2 commits June 18, 2026 03:00
Replace ad-hoc std::cout/std::cerr/printf output across the engine with a
small, dependency-free leveled logger (include/ncorr/log.h, src/log.cpp).

- Five severity levels (TRACE/DEBUG/INFO/WARN/ERROR) plus OFF, with
  independent console and log-file thresholds.
- Thread-safe (mutex), safe under the OpenMP parallel DIC regions.
- Stream-style macros (NLOG_INFO << ...) that short-circuit message
  construction when the level is disabled, keeping the per-frame /
  per-iteration hot loops cheap.
- Configurable via environment variables (NCORR_LOG_LEVEL, NCORR_LOG_FILE,
  NCORR_LOG_CONSOLE) since the library has no CLI; the existing `debug`
  flag lowers the console threshold to DEBUG.

Migrated all ~164 print sites in ncorr.cpp, Image2D.cpp, Array2D.h and
ROI2D.h to the appropriate level (errors->ERROR, warnings->WARN,
progress->INFO, diagnostics->DEBUG). Documented in README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Apply clang-format 18.1.8 (the version pinned by the lint workflow) to the
newly added include/ncorr/log.h and src/log.cpp so the 'lint (clang-format on
changed files)' check passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@johnaoga johnaoga merged commit 861b5ce into main Jun 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant