Skip to content

Commit 5e6bbcb

Browse files
logging: Add showcase example for console and remote logging
1 parent 3dd398a commit 5e6bbcb

5 files changed

Lines changed: 235 additions & 0 deletions

File tree

showcases/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ score_pkg_bundle(
1818
other_package_files = [
1919
"//showcases/standalone:comm_pkg_files",
2020
"//showcases/standalone:kyron_pkg_files",
21+
"//showcases/logging:logging_pkg_files",
2122
"//showcases/orchestration_persistency:orch_per_pkg_files",
2223
"//showcases/simple_lifecycle:simple_lifecycle_pkg_files",
2324
],

showcases/logging/BUILD

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
load("//bazel_common:bundlers.bzl", "score_pkg_bundle")
15+
16+
cc_binary(
17+
name = "logging_example",
18+
srcs = ["main.cpp"],
19+
visibility = ["//visibility:public"],
20+
deps = [
21+
"@score_logging//score/mw/log:log",
22+
"@score_logging//score/mw/log/backend:remote",
23+
],
24+
)
25+
26+
score_pkg_bundle(
27+
name = "logging",
28+
bins = [
29+
":logging_example",
30+
],
31+
config_data = [
32+
"logging.score.json",
33+
34+
],
35+
36+
custom_layout = {
37+
"//showcases/logging:config/logging.json": "etc/logging.json",
38+
},
39+
40+
)
41+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"appId": "LGSC",
3+
"appDesc": "Logging Showcase",
4+
5+
"logMode": "kRemote|kConsole",
6+
"logLevel": "kVerbose",
7+
"logLevelThresholdConsole": "kDebug",
8+
9+
"contextConfigs": [
10+
{
11+
"name": "SENSOR",
12+
"logLevel": "kVerbose"
13+
},
14+
{
15+
"name": "CTRL",
16+
"logLevel": "kInfo"
17+
}
18+
]
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "Logging example",
3+
"description": "Example demonstrating logging integration across camera, perception, and vehicle control pipeline services",
4+
"apps": [
5+
{
6+
"path": "/bin/sh",
7+
"args": [
8+
"-c",
9+
"cd /usr/bin/datarouter && ./datarouter --no_adaptive_runtime >/dev/null 2>&1 & sleep 2"
10+
],
11+
"env":{}
12+
},
13+
{
14+
"path": "/showcases/bin/logging_example",
15+
"args": [],
16+
"env": {
17+
"MW_LOG_CONFIG_FILE": "/showcases/data/logging/etc/logging.json"
18+
}
19+
}
20+
]
21+
}

showcases/logging/main.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// *******************************************************************************
2+
// Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
//
4+
// See the NOTICE file(s) distributed with this work for additional
5+
// information regarding copyright ownership.
6+
//
7+
// This program and the accompanying materials are made available under the
8+
// terms of the Apache License Version 2.0 which is available at
9+
// <https://www.apache.org/licenses/LICENSE-2.0>
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
// *******************************************************************************
13+
14+
#include "score/mw/log/logger.h"
15+
16+
#include <chrono>
17+
#include <cstdlib>
18+
#include <iostream>
19+
#include <string_view>
20+
#include <thread>
21+
22+
using namespace std::chrono_literals;
23+
24+
namespace integration
25+
{
26+
27+
namespace config
28+
{
29+
// logging routing contexts
30+
constexpr std::string_view kSensorContext{"SENSOR"};
31+
constexpr std::string_view kControlContext{"CTRL"};
32+
} // namespace config
33+
34+
class SensorPipeline
35+
{
36+
public:
37+
SensorPipeline()
38+
: logger_{score::mw::log::CreateLogger(
39+
config::kSensorContext.data(),
40+
"Sensor")}
41+
{
42+
// log info: sensor service startup
43+
logger_.LogInfo()
44+
<< "sensor initialized";
45+
}
46+
47+
void Process(std::uint32_t frame_id)
48+
{
49+
// log debug: frame entry tracking
50+
logger_.LogDebug()
51+
<< "frame received=" << frame_id;
52+
53+
// log info: frame processed successfully
54+
logger_.LogInfo()
55+
<< "frame processed"
56+
<< " id=" << frame_id;
57+
58+
if (frame_id == 3U)
59+
{
60+
// log warn : processing delay detected
61+
logger_.LogWarn()
62+
<< "processing delay frame=" << frame_id;
63+
}
64+
65+
if (frame_id == 5U)
66+
{
67+
// log error : frame processing failure
68+
logger_.LogError()
69+
<< "processing failed frame=" << frame_id;
70+
}
71+
}
72+
73+
private:
74+
score::mw::log::Logger &logger_;
75+
};
76+
77+
class VehicleController
78+
{
79+
public:
80+
VehicleController()
81+
: logger_{score::mw::log::CreateLogger(
82+
config::kControlContext.data(),
83+
"Control")}
84+
{
85+
// log info : controller initialization complete
86+
logger_.LogInfo()
87+
<< "controller ready mode=AUTO";
88+
}
89+
90+
void Execute(std::uint32_t frame_id)
91+
{
92+
const std::uint32_t speed{frame_id * 10U};
93+
94+
// log debug : control cycle execution trace
95+
logger_.LogDebug()
96+
<< "control cycle=" << frame_id;
97+
98+
// log info : control decision applied
99+
logger_.LogInfo()
100+
<< "control applied"
101+
<< " id=" << frame_id;
102+
103+
if (frame_id >= 6U)
104+
{
105+
// log warn : high speed condition detected
106+
logger_.LogWarn()
107+
<< "high speed frame=" << frame_id;
108+
}
109+
110+
if (frame_id == 7U)
111+
{
112+
// log fatal : emergency stop
113+
logger_.LogFatal()
114+
<< "emergency stop triggered at frame=" << frame_id;
115+
}
116+
}
117+
118+
private:
119+
score::mw::log::Logger &logger_;
120+
};
121+
122+
class Application
123+
{
124+
public:
125+
void Run()
126+
{
127+
std::cout << "\nLogging Example\n";
128+
129+
SensorPipeline sensor;
130+
VehicleController control;
131+
132+
for (std::uint32_t frame{1U}; frame <= 8U; ++frame)
133+
{
134+
std::cout << "Frame=" << frame << '\n';
135+
136+
sensor.Process(frame);
137+
control.Execute(frame);
138+
139+
std::this_thread::sleep_for(300ms);
140+
}
141+
142+
std::cout << "\nLogging Example finished\n";
143+
}
144+
};
145+
146+
} // namespace integration
147+
148+
int main()
149+
{
150+
integration::Application app;
151+
app.Run();
152+
return EXIT_SUCCESS;
153+
}

0 commit comments

Comments
 (0)