Skip to content

feat(core): add OpenCV-style logging facade (#80)#87

Open
kalwalt wants to merge 9 commits into
devfrom
feat/issue-80-logging-facade
Open

feat(core): add OpenCV-style logging facade (#80)#87
kalwalt wants to merge 9 commits into
devfrom
feat/issue-80-logging-facade

Conversation

@kalwalt

@kalwalt kalwalt commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

Add a new core::logging module mirroring OpenCV's cv::utils::logging, built on the existing log crate facade.

Closes #80

What's included

LogLevel enum

7 variants: Silent, Fatal, Error, Warning, Info, Debug, Verbose with bidirectional conversions to/from log::LevelFilter and log::Level.

Functions

  • set_log_level(LogLevel) -> LogLevel — returns previous level (OpenCV semantics)
  • get_log_level() -> LogLevel

tags submodule

Per-subsystem constants: PURECV, CORE, IMGPROC, FEATURES2D, CALIB3D, VIDEO

Macros (all #[macro_export])

Family Macros
Level cv_log_fatal!, cv_log_error!, cv_log_warning!, cv_log_info!, cv_log_debug!, cv_log_verbose!
Once-per-site cv_log_once_error!, cv_log_once_warning!, cv_log_once_info!, cv_log_once_debug!
Conditional cv_log_if_error!, cv_log_if_warning!, cv_log_if_info!, cv_log_if_debug!

Example usage

use purecv::core::logging::{self, tags, LogLevel};

logging::set_log_level(LogLevel::Info);
purecv::cv_log_info!(tags::IMGPROC, "gaussian blur, ksize = {}", 5);
purecv::cv_log_if_warning!(tags::CORE, ksize % 2 == 0, "even kernel size: {}", ksize);

Files changed (6)

File Change
src/core/logging.rs NEW — main module
src/core.rs Register module, add re-exports
src/core/utils.rs Remove old log functions, add re-exports from logging
src/lib.rs Add LogLevel + tags to prelude
src/version.rs Migrate log::info! to cv_log_info!
src/core/tests.rs Add 10 logging tests

Breaking change

set_log_level / get_log_level now take/return LogLevel instead of log::LevelFilter. These functions had zero callers in the entire codebase and the crate is pre-1.0 (0.6.1).

Verification

  • cargo fmt -- --check (clean)
  • cargo clippy -- -D warnings (0 warnings)
  • cargo test (305 unit tests + 39 doc-tests passed)

Add a new core::logging module mirroring cv::utils::logging, built on
the existing log crate facade. Provides:

- LogLevel enum (Silent/Fatal/Error/Warning/Info/Debug/Verbose) with
  From conversions to/from log::LevelFilter and log::Level
- set_log_level/get_log_level with return-previous semantics
- tags submodule with per-subsystem constants (PURECV, CORE, IMGPROC,
  FEATURES2D, CALIB3D, VIDEO)
- Level macros: cv_log_fatal/error/warning/info/debug/verbose
- Once-per-call-site macros: cv_log_once_error/warning/info/debug
  (AtomicBool-based, no_std-friendly)
- Conditional macros: cv_log_if_error/warning/info/debug

Breaking change: set_log_level/get_log_level now use LogLevel instead
of log::LevelFilter (pre-1.0, zero callers in codebase).

Closes #80
@kalwalt kalwalt added enhancement New feature or request rust-code rust Pull requests that update rust code labels Jul 16, 2026
@kalwalt kalwalt self-assigned this Jul 16, 2026
kalwalt and others added 8 commits July 18, 2026 11:19
Fuse "log the failure with the caller's subsystem tag" and "produce the
matching PureCvError" into a single call, so every error site stays a
one-liner while log level and format policy live in one place.

- cv_bail!  — log warning, then `return Err(PureCvError::Variant(msg))`
- cv_err!   — log warning, yield the PureCvError value (expression position)
- cv_bail_debug! / cv_err_debug! — debug-level variants for low-severity paths

Add unit tests and a doctest covering all four macros. Purely additive;
no call sites migrated yet.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Migrate every `Err(PureCvError::…)` input-validation site in arithm.rs
(42 sites) and matrix.rs (7 sites) to the cv_bail!/cv_err! log-and-return
macros, so bad input is logged at warning level with the caller's CORE tag.

Each message now names its function and interpolates the actual offending
values (dims, channel counts, args) instead of a static string, e.g.
"add: matrices must have the same dimensions (src1 4×4×3, src2 2×2×1)".
The pre-existing solve() singular-matrix log is left untouched.

Drop the now-unused PureCvError import from both files.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
These three modules had no `//!` summary, so they rendered with a blank
description on the crate root docs page while siblings (calib3d,
features2d, video, …) had one. Add overviews mirroring their style:

- core:    Matrix/Scalar, arithm/solvers, dft/dct, error, logging
- imgproc: color, filter, edge, threshold, morph, geometric, pyramid
- features: placeholder note for the not-yet-implemented FAST/ORB APIs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…es (#80)

Migrate every Err(PureCvError::…) input-validation site in the remaining
core modules to the cv_bail!/cv_err! log-and-return macros, completing the
core coverage started in arithm.rs and matrix.rs:

- dct.rs (4), dft.rs (3), metrics.rs (3), rng.rs (2), types.rs (1)
- dynamic.rs (9), structural.rs (16)

Each message now names its function and interpolates the actual offending
values (dims, channel counts, lengths). Drop the now-unused PureCvError
import from these files (types.rs keeps a full-path doc link).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request rust Pull requests that update rust code rust-code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant