Skip to content

Commit 03b3814

Browse files
committed
impl: use score_log for logs
- Use `stdout_logger` for Cargo builds. - Use `score_log_bridge` for Bazel builds. - Additional logs from Rust implementation. - Use proxy module for logging with correct context across the lib. - Fix tests.
1 parent 9692dad commit 03b3814

File tree

25 files changed

+378
-134
lines changed

25 files changed

+378
-134
lines changed

.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ build --tool_java_language_version=17
2525
build --java_runtime_version=remotejdk_17
2626
build --tool_java_runtime_version=remotejdk_17
2727

28+
build --@score_baselibs_rust//src/log:safety_level=qm
2829
build --@score_baselibs//score/json:base_library=nlohmann
29-
build --@score_baselibs//score/mw/log/flags:KRemote_Logging=False
30+
build --@score_logging//score/mw/log/flags:KRemote_Logging=False
3031

3132
# Clippy linting (enabled by default)
3233
build --aspects=@score_rust_policies//clippy:linters.bzl%clippy_strict

Cargo.lock

Lines changed: 40 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ edition = "2021"
1515
[workspace.dependencies]
1616
rust_kvs = { path = "src/rust/rust_kvs" }
1717
rust_kvs_tool = { path = "src/rust/rust_kvs_tool" }
18+
score_log = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.0", features = [
19+
"qm",
20+
] }
1821

1922
adler32 = "1.2.0"
2023
tinyjson = "2.5.1"

MODULE.bazel

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ git_override(
4848
# Shared Rust policies (Clippy config, etc.), overridden locally during development.
4949
bazel_dep(name = "score_rust_policies", version = "0.0.4", dev_dependency = True)
5050

51+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust", dev_dependency = True)
52+
rust.toolchain(
53+
edition = "2021",
54+
versions = ["1.90.0"],
55+
)
56+
5157
# bazel cc rules
5258
bazel_dep(name = "rules_cc", version = "0.1.2")
5359

@@ -65,6 +71,7 @@ bazel_dep(name = "platforms", version = "1.0.0")
6571

6672
## S-CORE bazel registry
6773
bazel_dep(name = "score_baselibs", version = "0.2.4")
74+
bazel_dep(name = "score_baselibs_rust", version = "0.1.0")
6875
bazel_dep(name = "score_bazel_platforms", version = "0.0.4")
6976
bazel_dep(name = "score_docs_as_code", version = "3.0.0")
7077

@@ -73,6 +80,20 @@ bazel_dep(name = "score_process", version = "1.4.3", dev_dependency = True)
7380

7481
bazel_dep(name = "score_python_basics", version = "0.3.4")
7582
bazel_dep(name = "score_tooling", version = "1.1.0")
83+
bazel_dep(name = "score_logging", version = "0.0.5")
84+
git_override(
85+
module_name = "score_logging",
86+
commit = "acf59e31cd933f5be6e899cab9fd121e6646a9fb",
87+
remote = "https://github.com/eclipse-score/logging.git",
88+
)
89+
90+
# TODO: remove once inherited properly from `score_logging`.
91+
bazel_dep(name = "trlc", version = "0.0.0", dev_dependency = True)
92+
git_override(
93+
module_name = "trlc",
94+
commit = "650b51a47264a4f232b3341f473527710fc32669", # trlc-2.0.2 release
95+
remote = "https://github.com/bmw-software-engineering/trlc.git",
96+
)
7697

7798
# ToDo: implicit dependencies for score_tooling, but needed directly here??
7899
bazel_dep(name = "aspect_rules_lint", version = "2.0.0")

src/rust/rust_kvs/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rust_library(
1717
srcs = glob(["src/**/*.rs"]),
1818
visibility = ["//visibility:public"],
1919
deps = [
20+
"@score_baselibs_rust//src/log/score_log",
2021
"@score_crates//:adler32",
2122
"@score_crates//:tinyjson",
2223
],

src/rust/rust_kvs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition.workspace = true
77
[dependencies]
88
adler32.workspace = true
99
tinyjson.workspace = true
10+
score_log.workspace = true
1011

1112

1213
[dev-dependencies]

src/rust/rust_kvs/src/error_code.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// *******************************************************************************
1313
extern crate alloc;
1414

15+
use crate::log::{error, ScoreDebug};
1516
use alloc::string::FromUtf8Error;
1617
use core::array::TryFromSliceError;
1718

1819
/// Runtime Error Codes
19-
#[derive(Debug, PartialEq)]
20+
#[derive(Debug, PartialEq, ScoreDebug)]
2021
pub enum ErrorCode {
2122
/// Error that was not yet mapped
2223
UnmappedError,
@@ -94,7 +95,7 @@ impl From<std::io::Error> for ErrorCode {
9495
match kind {
9596
std::io::ErrorKind::NotFound => ErrorCode::FileNotFound,
9697
_ => {
97-
eprintln!("error: unmapped error: {kind}");
98+
error!("Unmapped IO error: {:?}", kind.to_string());
9899
ErrorCode::UnmappedError
99100
},
100101
}
@@ -103,21 +104,21 @@ impl From<std::io::Error> for ErrorCode {
103104

104105
impl From<FromUtf8Error> for ErrorCode {
105106
fn from(cause: FromUtf8Error) -> Self {
106-
eprintln!("error: UTF-8 conversion failed: {cause:#?}");
107+
error!("Conversion from UTF-8 failed: {:#?}", cause);
107108
ErrorCode::ConversionFailed
108109
}
109110
}
110111

111112
impl From<TryFromSliceError> for ErrorCode {
112113
fn from(cause: TryFromSliceError) -> Self {
113-
eprintln!("error: try_into from slice failed: {cause:#?}");
114+
error!("Conversion from slice failed: {:#?}", cause);
114115
ErrorCode::ConversionFailed
115116
}
116117
}
117118

118119
impl From<Vec<u8>> for ErrorCode {
119120
fn from(cause: Vec<u8>) -> Self {
120-
eprintln!("error: try_into from u8 vector failed: {cause:#?}");
121+
error!("Conversion from vector of u8 failed: {:#?}", cause);
121122
ErrorCode::ConversionFailed
122123
}
123124
}

0 commit comments

Comments
 (0)