Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ build --tool_java_language_version=17
build --java_runtime_version=remotejdk_17
build --tool_java_runtime_version=remotejdk_17

build --@score_baselibs_rust//src/log:safety_level=qm
build --@score_baselibs//score/json:base_library=nlohmann
build --@score_logging//score/mw/log/flags:KRemote_Logging=False

test --test_output=errors

# Ferrocene must be common compiler for HOST. To ensure metadata compatibility for proc macro crates!
Expand Down
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ kyron-testing = { path = "src/kyron-testing" }
logging_tracing = { path = "src/logging_tracing", default-features = false }
xtask = { path = "src/xtask" }


score_log = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.0", features = [
"qm",
] }
stdout_logger = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.0" }
iceoryx2 = { git = "https://github.com/eclipse-iceoryx/iceoryx2.git", rev = "d3d1c9a727d3dc405733081923be5dba8213d6d8", default-features = false }
iceoryx2-cal = { git = "https://github.com/eclipse-iceoryx/iceoryx2.git", rev = "d3d1c9a727d3dc405733081923be5dba8213d6d8" }
iceoryx2-bb-container = { git = "https://github.com/eclipse-iceoryx/iceoryx2.git", rev = "d3d1c9a727d3dc405733081923be5dba8213d6d8" }
Expand Down
13 changes: 13 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ bazel_dep(name = "score_rust_policies", version = "0.0.3")
bazel_dep(name = "score_process", version = "1.4.3", dev_dependency = True)
bazel_dep(name = "score_platform", version = "0.5.3", dev_dependency = True) # This is main score repo

# S-CORE log dependencies
bazel_dep(name = "score_baselibs", version = "0.2.4")
bazel_dep(name = "score_baselibs_rust", version = "0.1.0")
bazel_dep(name = "score_logging", version = "0.1.0")

# TODO: remove once inherited properly from `score_logging`.
bazel_dep(name = "trlc", version = "0.0.0", dev_dependency = True)
git_override(
module_name = "trlc",
commit = "650b51a47264a4f232b3341f473527710fc32669", # trlc-2.0.2 release
remote = "https://github.com/bmw-software-engineering/trlc.git",
)

# Toolchains and extensions
bazel_dep(name = "score_bazel_cpp_toolchains", version = "0.2.2", dev_dependency = True)
bazel_dep(name = "score_toolchains_rust", version = "0.4.0", dev_dependency = True)
Expand Down
1,337 changes: 1,041 additions & 296 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ alias(
actual = "//src/kyron:safety_task",
visibility = ["//visibility:public"],
)

alias(
name = "logging",
actual = "//src/kyron:logging",
visibility = ["//visibility:public"],
)
15 changes: 15 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ Shows how to use Kyron's safety-critical features, including:

**Key concepts:** Safety-critical tasks, dedicated workers, task context, failure handling

### logging.rs

Demontrates how to use the Kyron's logging framework (liblogging_tracing), which supports logging through tracing/log/score-log loggers.

The example application can be built as folows,

`bazel build --config=x86_64-linux --//src/flags:logging_feature=<feature> //examples:logging`

where `<feature>` is tracing/log/score-log. The default feature is `tracing`.

For example with score-log, copy the `../src/kyron/examples/config/logging.json` to where executable is present and then execute `logging` application.
Alternatively, the configuration file path can be specified in the source code using `config_path()` function of `LogAndTraceBuilder`.

**Key concepts:** Logging using Kyron's logging framework

## Runtime Configuration

Most examples demonstrate different runtime configurations:
Expand Down
30 changes: 29 additions & 1 deletion src/flags/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")

bool_flag(
name = "k_runtime_disable_time_correction",
Expand Down Expand Up @@ -41,3 +41,31 @@ config_setting(
},
visibility = ["//visibility:public"],
)

# To select logging feature
string_flag(
name = "logging_feature",
build_setting_default = "tracing",
visibility = ["//visibility:public"],
)

config_setting(
name = "logging_feature_tracing",
flag_values = {
":logging_feature": "tracing",
},
)

config_setting(
name = "logging_feature_log",
flag_values = {
":logging_feature": "log",
},
)

config_setting(
name = "logging_feature_score_log",
flag_values = {
":logging_feature": "score-log",
},
)
43 changes: 36 additions & 7 deletions src/kyron-foundation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,37 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "libkyron_foundation",
srcs = glob(["src/**/*.rs"]),
crate_features = [
crate_features = select({
"//src/flags:logging_feature_tracing": [
"tracing",
],
"//src/flags:logging_feature_log": [
"log",
],
"//src/flags:logging_feature_score_log": [
"score-log",
],
"//conditions:default": [],
}) + [
"bazel_build_iceoryx2_qnx8",
"tracing",
],
crate_name = "kyron_foundation",
proc_macro_deps = [
"@score_crates//:iceoryx2_bb_derive_macros_qnx8",
],
visibility = ["//visibility:public"],
deps = [
deps = select({
"//src/flags:logging_feature_tracing": [
"@score_crates//:tracing",
],
"//src/flags:logging_feature_log": [
"@score_crates//:log",
],
"//src/flags:logging_feature_score_log": [
"@score_baselibs_rust//src/log/score_log",
],
"//conditions:default": [],
}) + [
"@score_crates//:iceoryx2_bb_container_qnx8",
"@score_crates//:iceoryx2_bb_elementary_qnx8",
"@score_crates//:iceoryx2_bb_elementary_traits_qnx8",
Expand All @@ -35,16 +56,24 @@ rust_library(
"@score_crates//:iceoryx2_bb_testing_qnx8",
"@score_crates//:iceoryx2_bb_threadsafe_qnx8",
"@score_crates//:iceoryx2_pal_concurrency_sync_qnx8",
"@score_crates//:tracing",
"@score_crates//:tracing_subscriber",
],
)

rust_test(
name = "tests",
crate = ":libkyron_foundation",
crate_features = [
crate_features = select({
"//src/flags:logging_feature_tracing": [
"tracing",
],
"//src/flags:logging_feature_log": [
"log",
],
"//src/flags:logging_feature_score_log": [
"score-log",
],
"//conditions:default": [],
}) + [
"bazel_build_iceoryx2_qnx8",
"tracing",
],
)
3 changes: 2 additions & 1 deletion src/kyron-foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ iceoryx2-pal-concurrency-sync.workspace = true

tracing = { workspace = true, optional = true }
log = { workspace = true, optional = true }
score_log = { workspace = true, optional = true }

[target.'cfg(loom)'.dependencies]
loom = "0.7"
Expand All @@ -33,6 +34,6 @@ kyron-testing.workspace = true

[features]
default = []
score-log = [] # Bazel compatibility only
score-log = ["dep:score_log"]
log = ["dep:log"]
tracing = ["dep:tracing"]
17 changes: 9 additions & 8 deletions src/kyron-foundation/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ macro_rules! not_recoverable_error {
( on_cond $result_obj:expr, $literal_str:expr ) => {{
const MSG: &str = $literal_str;
if !($result_obj) {
error!("not_recoverable_error: {} at {}:{}", $literal_str, file!(), line!());
k_error!("not_recoverable_error: {} at {}:{}", MSG, file!(), line!());
panic!(
"Currently no custom handler connected for panic, using rust one. Panicked with {}",
$literal_str
MSG
);
}
}};
Expand All @@ -37,30 +37,31 @@ macro_rules! not_recoverable_error {
if ($result_obj).is_err() {
let err = ($result_obj).unwrap_err();

error!("not_recoverable_error: {} with error {:?}", $literal_str, err);
k_error!("not_recoverable_error: {} with error {:?}", MSG, err);
panic!(
"Currently no custom handler connected for panic, using rust one. Panicked with {} with {:?}",
$literal_str, err
MSG, err
);
}
}};
// handles a case where we want to log the object with an error in form not_recoverable_error!(with OBJECT, "MSG");
( with $obj_to_log:expr, $literal_str:expr ) => {{
const MSG: &str = $literal_str;
error!("not_recoverable_error: {}. with {:?}", $literal_str, $obj_to_log);
let obj_str = format!("{:?}", $obj_to_log);
k_error!("not_recoverable_error: {}. with {:?}", MSG, obj_str);
panic!(
"Currently no custom handler connected for panic, using rust one. Panicked with {} with {:?}",
$literal_str, $obj_to_log
MSG, obj_str
);
}};

// handles a simple string literal error not_recoverable_error!("MSG");
( $literal_str:expr ) => {{
const MSG: &str = $literal_str;
error!("not_recoverable_error: {}", $literal_str);
k_error!("not_recoverable_error: {}", MSG);
panic!(
"Currently no custom handler connected for panic, using rust one. Panicked with {}",
$literal_str
MSG
);
}};
}
20 changes: 19 additions & 1 deletion src/kyron-foundation/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ pub use tracing::{debug, error, info, span, trace, warn, Level};
pub use log::{debug, error, info, trace, warn, Level};

#[cfg(feature = "score-log")]
compile_error!("Not ready yet!");
pub use score_log::{
self, debug, error, fatal,
fmt::{Error, FormatSpec, ScoreDebug, ScoreWrite},
info, log_enabled, trace, warn, Level, ScoreDebug,
};

// Adapter super trait with blanket implementations to use wherever ScoreDebug is needed.
// This helps to avoid many cfg conditions and code duplications.
#[cfg(feature = "score-log")]
pub trait ScoreLogDebug: ScoreDebug {}
#[cfg(not(feature = "score-log"))]
pub trait ScoreLogDebug {}

// Blanket impls
#[cfg(feature = "score-log")]
impl<T: ScoreDebug> ScoreLogDebug for T {}
#[cfg(not(feature = "score-log"))]
impl<T> ScoreLogDebug for T {}

#[cfg(feature = "log")]
#[macro_export]
Expand Down Expand Up @@ -111,6 +128,7 @@ macro_rules! tracing_adapter {
};
}

#[cfg(any(feature = "tracing", feature = "log"))]
/// Proxy for `trace!` macro, works with `tracing` and `log` features.
/// `tracing` key-value syntax (`name =? value`) is supported for `log` derived crates.
/// NOTE: provided variables cannot be interpolated into the message literal directly.
Expand Down
1 change: 1 addition & 0 deletions src/kyron-foundation/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

#[cfg_attr(feature = "score-log", derive(crate::prelude::ScoreDebug))]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum CommonErrors {
NoData,
Expand Down
Loading
Loading