Skip to content

Commit ba914d3

Browse files
committed
impl: use "PERS" context for this component
- Provide `log` module as a `mw_log` proxy. - Use `"PERS"` context for all persistency logs.
1 parent a474245 commit ba914d3

File tree

10 files changed

+84
-17
lines changed

10 files changed

+84
-17
lines changed

src/rust/rust_kvs/src/error_code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
extern crate alloc;
1313

14+
use crate::log::{error, ScoreDebug};
1415
use alloc::string::FromUtf8Error;
1516
use core::array::TryFromSliceError;
16-
use mw_log::error;
1717

1818
/// Runtime Error Codes
19-
#[derive(Debug, PartialEq, mw_log::ScoreDebug)]
19+
#[derive(Debug, PartialEq, ScoreDebug)]
2020
pub enum ErrorCode {
2121
/// Error that was not yet mapped
2222
UnmappedError,

src/rust/rust_kvs/src/json_backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::error_code::ErrorCode;
1313
use crate::kvs_api::{InstanceId, SnapshotId};
1414
use crate::kvs_backend::KvsBackend;
1515
use crate::kvs_value::{KvsMap, KvsValue};
16-
use mw_log::{debug, error, trace};
16+
use crate::log::{debug, error, trace, ScoreDebug};
1717
use std::collections::HashMap;
1818
use std::fs;
1919
use std::path::{Path, PathBuf};
@@ -200,7 +200,7 @@ impl Default for JsonBackendBuilder {
200200
}
201201

202202
/// KVS backend implementation based on TinyJSON.
203-
#[derive(Clone, Debug, PartialEq, mw_log::ScoreDebug)]
203+
#[derive(Clone, Debug, PartialEq, ScoreDebug)]
204204
pub struct JsonBackend {
205205
working_dir: PathBuf,
206206
snapshot_max_count: usize,

src/rust/rust_kvs/src/kvs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use crate::kvs_api::{InstanceId, KvsApi, KvsDefaults, KvsLoad, SnapshotId};
1414
use crate::kvs_backend::KvsBackend;
1515
use crate::kvs_builder::KvsData;
1616
use crate::kvs_value::{KvsMap, KvsValue};
17-
use mw_log::{error, fmt::ScoreDebug, warn};
17+
use crate::log::{error, warn, ScoreDebug};
1818
use std::sync::{Arc, Mutex};
1919

2020
/// KVS instance parameters.
21-
#[derive(mw_log::ScoreDebug)]
21+
#[derive(ScoreDebug)]
2222
pub struct KvsParameters {
2323
/// Instance ID.
2424
pub instance_id: InstanceId,
@@ -343,12 +343,13 @@ mod kvs_tests {
343343
use crate::kvs_backend::KvsBackend;
344344
use crate::kvs_builder::KvsData;
345345
use crate::kvs_value::{KvsMap, KvsValue};
346+
use crate::log::ScoreDebug;
346347
use std::sync::{Arc, Mutex};
347348
use tempfile::tempdir;
348349

349350
/// Most tests can be performed with mocked backend.
350351
/// Only those with file handling must use concrete implementation.
351-
#[derive(PartialEq, Debug, mw_log::ScoreDebug)]
352+
#[derive(PartialEq, Debug, ScoreDebug)]
352353
struct MockBackend;
353354

354355
impl KvsBackend for MockBackend {

src/rust/rust_kvs/src/kvs_api.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
use crate::error_code::ErrorCode;
1313
use crate::kvs_value::KvsValue;
14-
use mw_log::fmt::ScoreDebug;
14+
use crate::log::ScoreDebug;
1515

1616
/// Instance ID
17-
#[derive(Clone, Copy, Debug, PartialEq, Eq, mw_log::ScoreDebug)]
17+
#[derive(Clone, Copy, Debug, PartialEq, Eq, ScoreDebug)]
1818
pub struct InstanceId(pub usize);
1919

2020
impl core::fmt::Display for InstanceId {
@@ -30,7 +30,7 @@ impl From<InstanceId> for usize {
3030
}
3131

3232
/// Snapshot ID
33-
#[derive(Clone, Copy, Debug, PartialEq, Eq, mw_log::ScoreDebug)]
33+
#[derive(Clone, Copy, Debug, PartialEq, Eq, ScoreDebug)]
3434
pub struct SnapshotId(pub usize);
3535

3636
impl core::fmt::Display for SnapshotId {
@@ -46,7 +46,7 @@ impl From<SnapshotId> for usize {
4646
}
4747

4848
/// Defaults handling mode.
49-
#[derive(Clone, Copy, Debug, PartialEq, Eq, mw_log::ScoreDebug)]
49+
#[derive(Clone, Copy, Debug, PartialEq, Eq, ScoreDebug)]
5050
pub enum KvsDefaults {
5151
/// Defaults are not loaded.
5252
Ignored,
@@ -59,7 +59,7 @@ pub enum KvsDefaults {
5959
}
6060

6161
/// KVS load mode.
62-
#[derive(Clone, Copy, Debug, PartialEq, Eq, mw_log::ScoreDebug)]
62+
#[derive(Clone, Copy, Debug, PartialEq, Eq, ScoreDebug)]
6363
pub enum KvsLoad {
6464
/// KVS is not loaded.
6565
Ignored,

src/rust/rust_kvs/src/kvs_backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
use crate::error_code::ErrorCode;
1313
use crate::kvs_api::{InstanceId, SnapshotId};
1414
use crate::kvs_value::KvsMap;
15+
use crate::log::ScoreDebug;
1516
use core::any::Any;
16-
use mw_log::fmt::ScoreDebug;
1717

1818
/// Trait for comparisons between types.
1919
pub trait DynEq: Any {

src/rust/rust_kvs/src/kvs_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::kvs::{Kvs, KvsParameters};
1515
use crate::kvs_api::{InstanceId, KvsDefaults, KvsLoad, SnapshotId};
1616
use crate::kvs_backend::KvsBackend;
1717
use crate::kvs_value::KvsMap;
18-
use mw_log::{debug, error, info, trace};
18+
use crate::log::{debug, error, info, trace, ScoreDebug};
1919
use std::sync::{Arc, LazyLock, Mutex, MutexGuard, PoisonError};
2020

2121
/// Maximum number of instances.
@@ -58,7 +58,7 @@ impl From<PoisonError<MutexGuard<'_, [Option<KvsInner>; KVS_MAX_INSTANCES]>>> fo
5858
}
5959

6060
/// Key-value-storage builder.
61-
#[derive(mw_log::ScoreDebug)]
61+
#[derive(ScoreDebug)]
6262
pub struct KvsBuilder {
6363
/// Instance ID.
6464
instance_id: InstanceId,

src/rust/rust_kvs/src/kvs_mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::error_code::ErrorCode;
1313
use crate::kvs_api::{KvsApi, SnapshotId};
1414
use crate::kvs_value::{KvsMap, KvsValue};
15-
use mw_log::fmt::ScoreDebug;
15+
use crate::log::ScoreDebug;
1616
use std::sync::{Arc, Mutex};
1717

1818
#[derive(Clone)]

src/rust/rust_kvs/src/kvs_value.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
//
1010
// SPDX-License-Identifier: Apache-2.0
1111

12+
use crate::log::ScoreDebug;
1213
use core::convert::TryFrom;
1314
use std::collections::HashMap;
1415

1516
/// Key-value storage map type
1617
pub type KvsMap = HashMap<String, KvsValue>;
1718

1819
/// Key-value-storage value
19-
#[derive(Clone, Debug, PartialEq, mw_log::ScoreDebug)]
20+
#[derive(Clone, Debug, PartialEq, ScoreDebug)]
2021
pub enum KvsValue {
2122
/// 32-bit signed integer
2223
I32(i32),

src/rust/rust_kvs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub mod kvs_builder;
140140
pub mod kvs_mock;
141141
pub mod kvs_serialize;
142142
pub mod kvs_value;
143+
mod log;
143144

144145
/// Prelude module for convenient imports
145146
pub mod prelude {

src/rust/rust_kvs/src/log.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2025 Contributors to the Eclipse Foundation
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information regarding copyright ownership.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Apache License Version 2.0 which is available at
8+
// <https://www.apache.org/licenses/LICENSE-2.0>
9+
//
10+
// SPDX-License-Identifier: Apache-2.0
11+
12+
//! Logging module.
13+
//! Utilizes `"PERS"` context by default.
14+
15+
#![allow(unused_macros)]
16+
17+
pub(crate) const CONTEXT: &str = "PERS";
18+
19+
/// Proxy for `mw_log::fatal!`.
20+
#[clippy::format_args]
21+
macro_rules! fatal {
22+
($($arg:tt)+) => (mw_log::fatal!(context: $crate::log::CONTEXT, $($arg)+));
23+
}
24+
25+
/// Proxy for `mw_log::error!`.
26+
#[clippy::format_args]
27+
macro_rules! error {
28+
($($arg:tt)+) => (mw_log::error!(context: $crate::log::CONTEXT, $($arg)+));
29+
}
30+
31+
/// Proxy for `mw_log::warn!`.
32+
#[clippy::format_args]
33+
macro_rules! warning {
34+
($($arg:tt)+) => (mw_log::warn!(context: $crate::log::CONTEXT, $($arg)+));
35+
}
36+
37+
/// Proxy for `mw_log::info!`.
38+
#[clippy::format_args]
39+
macro_rules! info {
40+
($($arg:tt)+) => (mw_log::info!(context: $crate::log::CONTEXT, $($arg)+));
41+
}
42+
43+
/// Proxy for `mw_log::debug!`.
44+
#[clippy::format_args]
45+
macro_rules! debug {
46+
($($arg:tt)+) => (mw_log::debug!(context: $crate::log::CONTEXT, $($arg)+));
47+
}
48+
49+
/// Proxy for `mw_log::trace!`.
50+
#[clippy::format_args]
51+
macro_rules! trace {
52+
($($arg:tt)+) => (mw_log::trace!(context: $crate::log::CONTEXT, $($arg)+));
53+
}
54+
55+
// Export macros from this module (e.g., `crate::log::error`).
56+
// `#[macro_export]` would export them from crate (e.g., `crate::error`).
57+
//
58+
// `warning as warn` is due to `warn` macro name conflicting with `warn` attribute.
59+
#[allow(unused_imports)]
60+
pub(crate) use {debug, error, fatal, info, trace, warning as warn};
61+
62+
// Re-export symbols from `mw_log`.
63+
pub(crate) use mw_log::fmt::ScoreDebug;
64+
pub(crate) use mw_log::ScoreDebug;

0 commit comments

Comments
 (0)