feat: Refactor kvstore and vault to use features and logging

- Remove hardcoded dependencies in kvstore Cargo.toml; use features
  instead. This allows for more flexible compilation for different
  targets (native vs. WASM).
- Improve logging in vault crate using the `log` crate. This makes
  debugging easier and provides more informative output during
  execution.  Native tests use `env_logger`, WASM tests use
  `console_log`.
- Update README to reflect new logging best practices.
- Add cfg attributes to native and wasm modules to improve clarity.
- Update traits.rs to specify Send + Sync behavior expectations.
This commit is contained in:
2025-05-15 16:42:19 +03:00
parent 7d7f94f114
commit cea2d7e655
17 changed files with 843 additions and 295 deletions

View File

@@ -12,22 +12,20 @@
## Logging Best Practices
This crate uses the [`log`](https://docs.rs/log) crate for all logging. To see logs in your application or tests, you must initialize a logger:
This crate uses the [`log`](https://docs.rs/log) crate for logging. For native tests, use [`env_logger`](https://docs.rs/env_logger); for WASM tests, use [`console_log`](https://docs.rs/console_log).
- **Native (desktop/server):**
- Add `env_logger` as a dev-dependency.
- Initialize in your main or test:
```rust
let _ = env_logger::builder().is_test(true).try_init();
```
- **WASM (browser):**
- Add `console_log` as a dev-dependency.
- Initialize in your main or test:
```rust
console_log::init_with_level(log::Level::Debug).expect("error initializing logger");
```
- Native (in tests):
```rust
let _ = env_logger::builder().is_test(true).try_init();
log::info!("test started");
```
- WASM (in tests):
```rust
console_log::init_with_level(log::Level::Debug).expect("error initializing logger");
log::debug!("wasm test started");
```
Then use logging macros (`log::debug!`, `log::info!`, `log::warn!`, `log::error!`) throughout your code and tests.
Use `log::debug!`, `log::info!`, `log::error!`, etc., throughout the codebase for consistent and idiomatic logging. Do not prefix messages with [DEBUG], [ERROR], etc. The log level is handled by the logger.
## Usage Example