feat(core): add OpenCV-style logging facade (#80)#87
Open
kalwalt wants to merge 9 commits into
Open
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new
core::loggingmodule mirroring OpenCV'scv::utils::logging, built on the existinglogcrate facade.Closes #80
What's included
LogLevelenum7 variants:
Silent,Fatal,Error,Warning,Info,Debug,Verbosewith bidirectional conversions to/fromlog::LevelFilterandlog::Level.Functions
set_log_level(LogLevel) -> LogLevel— returns previous level (OpenCV semantics)get_log_level() -> LogLeveltagssubmodulePer-subsystem constants:
PURECV,CORE,IMGPROC,FEATURES2D,CALIB3D,VIDEOMacros (all
#[macro_export])cv_log_fatal!,cv_log_error!,cv_log_warning!,cv_log_info!,cv_log_debug!,cv_log_verbose!cv_log_once_error!,cv_log_once_warning!,cv_log_once_info!,cv_log_once_debug!cv_log_if_error!,cv_log_if_warning!,cv_log_if_info!,cv_log_if_debug!Example usage
Files changed (6)
src/core/logging.rssrc/core.rssrc/core/utils.rssrc/lib.rsLogLevel+tagsto preludesrc/version.rslog::info!tocv_log_info!src/core/tests.rsBreaking change
set_log_level/get_log_levelnow take/returnLogLevelinstead oflog::LevelFilter. These functions had zero callers in the entire codebase and the crate is pre-1.0 (0.6.1).Verification