-
Notifications
You must be signed in to change notification settings - Fork 2
Log backend for rust frontend #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes in this file seem unrelated to rust log backend. Should be moved to individual PR (or at least individual commit) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are related, to use new code in other repo You need them. I would not split this into seprate PR because it's direct consequence of adding a code and making it usable to other repos. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes in this file seem unrelated to rust log backend. Should be moved to individual PR (or at least individual commit) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are related, to use new code in other repo You need them. I would not split this into seprate PR because it's direct consequence of adding a code and making it usable to other repos. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
# SPDX-License-Identifier: Apache-2.0 | ||
# ******************************************************************************* | ||
module( | ||
name = "cpp_rust_template_repository", | ||
version = "1.0", | ||
name = "score-mw-log", | ||
version = "0.1", | ||
) | ||
|
||
bazel_dep(name = "rules_python", version = "1.4.1") | ||
|
@@ -27,31 +27,48 @@ python.toolchain( | |
use_repo(python) | ||
|
||
# Add GoogleTest dependency | ||
bazel_dep(name = "googletest", version = "1.17.0") | ||
bazel_dep(name = "googletest", version = "1.15.0") | ||
|
||
# Rust rules for Bazel | ||
bazel_dep(name = "rules_rust", version = "0.63.0") | ||
bazel_dep(name = "rules_rust", version = "0.56.0") | ||
|
||
# Checker rule for CopyRight checks/fixs | ||
bazel_dep(name = "score_cr_checker", version = "0.3.1") | ||
bazel_dep(name = "score_python_basics", version = "0.3.4") | ||
bazel_dep(name = "score_starpls_lsp", version = "0.1.0") | ||
|
||
# C/C++ rules for Bazel | ||
bazel_dep(name = "rules_cc", version = "0.2.1") | ||
bazel_dep(name = "rules_cc", version = "0.1.1") | ||
|
||
# LLVM Toolchains Rules - host configuration | ||
bazel_dep(name = "toolchains_llvm", version = "1.4.0") | ||
bazel_dep(name = "toolchains_llvm", version = "1.3.0") | ||
|
||
# Configure and register the toolchain. | ||
bazel_dep(name = "score_toolchains_gcc", version = "0.4", dev_dependency = True) | ||
|
||
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm") | ||
llvm.toolchain( | ||
cxx_standard = {"": "c++17"}, | ||
llvm_version = "19.1.0", | ||
gcc = use_extension("@score_toolchains_gcc//extentions:gcc.bzl", "gcc", dev_dependency = True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the toolchain fixed across S-CORE? I was expecting it fixed, as at some point the software has to be build using safety certified compiler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean a fixed version? This declared L47 like described in toolchain repo There is a newer version 0.6 available, but I don't know the version deployment/usage schema in the project. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I mean in the end if an some entity want to put logging into a Vehicle under ISO26262 certification it needs to be compliable/linkable by a certified compiler. Typically those are older versions. Eg. for QNX7 Safety core it was GCC9. Hence a lot of brand new compiler goodies were not allowed to be used. Here it seems you pull a very recent version, and I'm afraid it will break users who need to compile with the qualified compiler. Do you rely on any such brand new feature? For the above reason, I thought all S-CORE Repos would have a common GCC = Version X.Y set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We dont rely on any, as You saw, usage is simple usage of baselib code. I think the compiler story, deps alignment and final checking is still not setup up finally in S-CORE. But I think the operational team is working on it. So for now I would skip this discussion here in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So, to my understanding the s-core toolchain repo offers "fixed toolchains" which are versioned. In this PR we make already use of it ( https://github.com/eclipse-score/logging/pull/1/files#diff-6136fc12446089c3db7360e923203dd114b6a1466252e71667c6791c20fe6bdcR47 ). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Okay, then I might just not understand the change being introduced here. To me it looks as if we pull a very recent compiler version in that is out of line with what the rest of the S-core project is using. If this is not the case and/or it is seen as tech debt with a clear roadmap of when and where to change to. Disregard my comment. |
||
gcc.toolchain( | ||
sha256 = "457f5f20f57528033cb840d708b507050d711ae93e009388847e113b11bf3600", | ||
strip_prefix = "x86_64-unknown-linux-gnu", | ||
url = "https://github.com/eclipse-score/toolchains_gcc_packages/releases/download/0.0.1/x86_64-unknown-linux-gnu_gcc12.tar.gz", | ||
) | ||
use_repo(llvm, "llvm_toolchain") | ||
use_repo(llvm, "llvm_toolchain_llvm") | ||
use_repo(gcc, "gcc_toolchain", "gcc_toolchain_gcc") | ||
|
||
register_toolchains("@llvm_toolchain//:all") | ||
# Dash license checker | ||
bazel_dep(name = "score_dash_license_checker", version = "0.1.2") | ||
|
||
# tooling | ||
bazel_dep(name = "score_tooling", version = "1.0.1") | ||
bazel_dep(name = "aspect_rules_lint", version = "1.5.3") | ||
# Format checker | ||
bazel_dep(name = "score_format_checker", version = "0.1.1") | ||
bazel_dep(name = "aspect_rules_lint", version = "1.4.4") | ||
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2") | ||
|
||
#docs-as-code | ||
bazel_dep(name = "score_docs_as_code", version = "1.1.0") | ||
bazel_dep(name = "score_docs_as_code", version = "1.0.1") | ||
|
||
# Code deps | ||
bazel_dep(name = "score-baselibs", version = "0.1.0") | ||
git_override( | ||
module_name = "score-baselibs", | ||
commit = "ae050e3cc556572830e1ec02ffbcbbd03f26df13", # or use "tag" or "branch" | ||
remote = "https://github.com/eclipse-score/baselibs.git", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# ******************************************************************************* | ||
# Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# ******************************************************************************* | ||
|
||
load("@rules_rust//cargo:defs.bzl", "cargo_build_script") | ||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") | ||
|
||
cc_library( | ||
name = "librust_cpp_log_adapter", | ||
srcs = ["src/rust_cpp_log_adapter.cpp"], | ||
visibility = ["//visibility:private"], | ||
deps = [ | ||
"@score-baselibs//score/mw/log", | ||
], | ||
) | ||
|
||
rust_library( | ||
name = "mw_log_subscriber", | ||
srcs = glob(["src/**/*.rs"]), | ||
crate_name = "mw_log_subscriber", | ||
edition = "2021", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":librust_cpp_log_adapter", | ||
"@score-baselibs//score/mw/log/rust:mw_log", | ||
], | ||
) | ||
|
||
rust_binary( | ||
name = "example", | ||
srcs = ["examples/main.rs"], | ||
data = [ | ||
"examples/config/logging.json", | ||
], | ||
edition = "2021", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":mw_log_subscriber", | ||
"@score-baselibs//score/mw/log/rust:mw_log", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"appId": "JSON", | ||
"appDesc": "JSON example programs", | ||
"logMode" : "kConsole", | ||
"logLevel": "kVerbose", | ||
"logLevelThresholdConsole": "kInfo" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this one level up. We can get rid of src dir There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we cannot, this is S-CORE layout. https://github.com/eclipse-score/module_template There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is src files for the module. Since we will have different modules in the same repo, it does not make sense and we remove it anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do it like that. Please decide. This will be only 4th different way of repo setup in S-CORE repos. |
||
// Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License Version 2.0 which is available at | ||
// <https://www.apache.org/licenses/LICENSE-2.0> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
use std::path::PathBuf; | ||
|
||
use mw_log::{debug, error, info, trace, warn}; | ||
use mw_log_subscriber::MwLoggerBuilder; | ||
|
||
fn main() { | ||
//Setup for example using config file | ||
let path = PathBuf::from(std::env::current_dir().unwrap()) | ||
.join(file!()) | ||
.parent() | ||
.unwrap() | ||
.join("config") | ||
.join("logging.json"); | ||
|
||
std::env::set_var("MW_LOG_CONFIG_FILE", path.as_os_str()); | ||
|
||
// Just initialize and set as default logger | ||
MwLoggerBuilder::new().set_as_default_logger::<false, true, false>(); | ||
|
||
trace!("This is a trace log"); | ||
debug!("This is a debug log"); | ||
error!("This is an error log"); | ||
info!("This is an info log"); | ||
warn!("This is a warn log"); | ||
|
||
error!( | ||
"This is an log that will be trimmed: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | ||
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc | ||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd | ||
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | ||
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg | ||
END MARKER NOT VISIBLE" | ||
); | ||
|
||
error!( | ||
"This is an log that will be trimmed {} {} {} {} {} {} {}. END MARKER NOT VISIBLE", | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", | ||
"ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", | ||
"ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", | ||
"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", | ||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
"ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg" | ||
); | ||
|
||
// Using logger instance with context | ||
let logger = MwLoggerBuilder::new() | ||
.with_context("ALFA") | ||
.build::<false, true, false>(); | ||
|
||
trace!( | ||
logger : logger, | ||
"This is a trace log" | ||
); | ||
debug!(logger : logger, "This is a debug log"); | ||
error!(logger : logger, "This is an error log"); | ||
info!(logger : logger, "This is an info log"); | ||
warn!(logger : logger, "This is a warn log"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we want to set this flag "globally" for anyone? Especially as remote logging is the standard way of logging ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, currently this is not supported. The code does not compile without it and I copied it from other repos.
Maybe I am missing some knowledge here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, your right. I forgot about that. We just have to make sure, this get's changed once we provide the remote backend.