Skip to content

Commit 9e60039

Browse files
authored
Fix logging to be initialized in binary and not in lib (#64)
* add logger for integration tests * change println! to log events * remove env_logger init from ustreamer * fix GitHub action runner to use ubuntu-22.04 for vsomeip workaround
1 parent 750e12d commit 9e60039

File tree

12 files changed

+48
-30
lines changed

12 files changed

+48
-30
lines changed

.github/workflows/unbundled-lint-and-test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ concurrency:
3939

4040
jobs:
4141
obtain_and_build_vsomeip:
42-
runs-on: ubuntu-latest
42+
runs-on: ubuntu-22.04
4343
outputs:
4444
cache_key: ${{ steps.generate_cache_key.outputs.CACHE_KEY }}
4545
steps:
@@ -120,7 +120,7 @@ jobs:
120120
lint:
121121
name: Lint
122122
needs: obtain_and_build_vsomeip
123-
runs-on: ubuntu-latest
123+
runs-on: ubuntu-22.04
124124
env:
125125
CACHE_KEY: ${{ needs.obtain_and_build_vsomeip.outputs.cache_key }}
126126

@@ -179,7 +179,7 @@ jobs:
179179
test:
180180
name: Test
181181
needs: obtain_and_build_vsomeip
182-
runs-on: ubuntu-latest
182+
runs-on: ubuntu-22.04
183183
env:
184184
CACHE_KEY: ${{ needs.obtain_and_build_vsomeip.outputs.cache_key }}
185185

@@ -258,7 +258,7 @@ jobs:
258258
build-docs:
259259
name: Build documentation
260260
needs: obtain_and_build_vsomeip
261-
runs-on: ubuntu-latest
261+
runs-on: ubuntu-22.04
262262
env:
263263
CACHE_KEY: ${{ needs.obtain_and_build_vsomeip.outputs.cache_key }}
264264

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

subscription-cache/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* SPDX-License-Identifier: Apache-2.0
1212
********************************************************************************/
1313

14+
use log::warn;
1415
use std::collections::{HashMap, HashSet};
1516
use std::hash::{Hash, Hasher};
1617
use std::sync::Mutex;
@@ -98,19 +99,19 @@ impl SubscriptionCache {
9899
let status = if let Some(status) = subscription.status.into_option() {
99100
status
100101
} else {
101-
println!("Unable to parse status from subscription, setting as default");
102+
warn!("Unable to parse status from subscription, setting as default");
102103
SubscriptionStatus::default()
103104
};
104105
let attributes = if let Some(attributes) = subscription.attributes.into_option() {
105106
attributes
106107
} else {
107-
println!("Unable to parse attributes from subscription, setting as default");
108+
warn!("Unable to parse attributes from subscription, setting as default");
108109
SubscribeAttributes::default()
109110
};
110111
let config = if let Some(config) = subscription.config.into_option() {
111112
config
112113
} else {
113-
println!("Unable to parse config from subscription, setting as default");
114+
warn!("Unable to parse config from subscription, setting as default");
114115
EventDeliveryConfig::default()
115116
};
116117
// Create new hashset if the key does not exist and insert the subscription

up-streamer/src/ustreamer.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,6 @@ impl UStreamer {
575575
usubscription: Arc<dyn USubscription>,
576576
) -> Result<Self, UStatus> {
577577
let name = format!("{USTREAMER_TAG}:{name}:");
578-
// Try to initiate logging.
579-
// Required in case of dynamic lib, otherwise no logs.
580-
// But cannot be done twice in case of static link.
581-
std::env::set_var("RUST_LOG", "debug");
582-
let _ = env_logger::try_init();
583578
debug!(
584579
"{}:{}:{} UStreamer created",
585580
&name, USTREAMER_TAG, USTREAMER_FN_NEW_TAG

up-streamer/tests/single_local_single_remote.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const SENT_MESSAGE_VEC_CAPACITY: usize = 10_000;
3838

3939
#[tokio::test(flavor = "multi_thread")]
4040
async fn single_local_single_remote() {
41+
integration_test_utils::init_logging();
42+
4143
// using async_broadcast to simulate communication protocol
4244
let (tx_1, rx_1) = broadcast(10000);
4345
let (tx_2, rx_2) = broadcast(10000);

up-streamer/tests/single_local_two_remote_add_remove_rules.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const SENT_MESSAGE_VEC_CAPACITY: usize = 20_000;
3939

4040
#[tokio::test(flavor = "multi_thread")]
4141
async fn single_local_two_remote_add_remove_rules() {
42+
integration_test_utils::init_logging();
43+
4244
// using async_broadcast to simulate communication protocol
4345
let (tx_1, rx_1) = broadcast(20000);
4446
let (tx_2, rx_2) = broadcast(20000);

up-streamer/tests/single_local_two_remote_authorities_different_remote_transport.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const SENT_MESSAGE_VEC_CAPACITY: usize = 10_000;
3939

4040
#[tokio::test(flavor = "multi_thread")]
4141
async fn single_local_two_remote_authorities_different_remote_transport() {
42+
integration_test_utils::init_logging();
4243
// using async_broadcast to simulate communication protocol
4344
let (tx_1, rx_1) = broadcast(20000);
4445
let (tx_2, rx_2) = broadcast(20000);

up-streamer/tests/single_local_two_remote_authorities_same_remote_transport.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const SENT_MESSAGE_VEC_CAPACITY: usize = 10_000;
3939

4040
#[tokio::test(flavor = "multi_thread")]
4141
async fn single_local_two_remote_authorities_same_remote_transport() {
42+
integration_test_utils::init_logging();
43+
4244
// using async_broadcast to simulate communication protocol
4345
let (tx_1, rx_1) = broadcast(20000);
4446
let (tx_2, rx_2) = broadcast(20000);

up-streamer/tests/usubscription.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use usubscription_static_file::USubscriptionStaticFile;
1919

2020
#[tokio::test(flavor = "multi_thread")]
2121
async fn usubscription_bad_data() {
22+
integration_test_utils::init_logging();
23+
2224
let utransport_foo: Arc<dyn UTransport> =
2325
Arc::new(UPClientFailingRegister::new("upclient_foo").await);
2426
let utransport_bar: Arc<dyn UTransport> =

utils/integration-test-utils/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,16 @@ pub use integration_test_messages::{
3939
request_from_remote_client_for_local_client, response_from_local_client_for_remote_client,
4040
response_from_remote_client_for_local_client,
4141
};
42+
43+
/// Helper method for integration tests to initialise
44+
/// [env_logger].
45+
///
46+
/// `RUST_LOG` env is read. Defaults to `DEBUG`
47+
pub fn init_logging() {
48+
let log_filter = std::env::var("RUST_LOG").unwrap_or_else(|_| "debug".to_string());
49+
env_logger::builder()
50+
.parse_filters(&log_filter)
51+
.format_timestamp(None)
52+
.is_test(true)
53+
.init();
54+
}

0 commit comments

Comments
 (0)