Skip to content

Commit b9420a2

Browse files
authored
Merge pull request #206 from qorix-group/arkjedrz_enable-logging-2
impl: logging support
2 parents 438bf9b + a2328f0 commit b9420a2

File tree

26 files changed

+372
-136
lines changed

26 files changed

+372
-136
lines changed

.bazelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ 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
3334
build --output_groups=+rules_lint_human
3435
build:lint --@aspect_rules_lint//lint:fail_on_violation=true
36+
build:lint --extra_toolchains=@score_toolchains_rust//toolchains/ferrocene:ferrocene_x86_64_unknown_linux_gnu
3537

3638
test --test_output=errors
3739

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ 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+
] }
21+
stdout_logger = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.0" }
1822

1923
adler32 = "1.2.0"
2024
tinyjson = "2.5.1"

MODULE.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ bazel_dep(name = "platforms", version = "1.0.0")
6565

6666
## S-CORE bazel registry
6767
bazel_dep(name = "score_baselibs", version = "0.2.4")
68+
bazel_dep(name = "score_baselibs_rust", version = "0.1.0")
6869
bazel_dep(name = "score_bazel_platforms", version = "0.0.4")
6970
bazel_dep(name = "score_docs_as_code", version = "3.0.0")
7071

@@ -73,6 +74,15 @@ bazel_dep(name = "score_process", version = "1.4.3", dev_dependency = True)
7374

7475
bazel_dep(name = "score_python_basics", version = "0.3.4")
7576
bazel_dep(name = "score_tooling", version = "1.1.0")
77+
bazel_dep(name = "score_logging", version = "0.1.0")
78+
79+
# TODO: remove once inherited properly from `score_logging`.
80+
bazel_dep(name = "trlc", version = "0.0.0", dev_dependency = True)
81+
git_override(
82+
module_name = "trlc",
83+
commit = "650b51a47264a4f232b3341f473527710fc32669", # trlc-2.0.2 release
84+
remote = "https://github.com/bmw-software-engineering/trlc.git",
85+
)
7686

7787
# ToDo: implicit dependencies for score_tooling, but needed directly here??
7888
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/examples/migration.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
//! Example for migrations between backends.
1515
1616
use rust_kvs::prelude::*;
17+
use score_log::ScoreDebug;
1718

1819
/// Example custom backend.
1920
/// Returns some data on `load_kvs`.
20-
#[derive(PartialEq)]
21+
#[derive(PartialEq, ScoreDebug)]
2122
struct FromBackend;
2223

2324
impl KvsBackend for FromBackend {
@@ -51,7 +52,7 @@ impl KvsBackend for FromBackend {
5152

5253
/// Example custom backend.
5354
/// Prints provided data to stdout.
54-
#[derive(PartialEq)]
55+
#[derive(PartialEq, ScoreDebug)]
5556
struct ToBackend;
5657

5758
impl KvsBackend for ToBackend {

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)