Skip to content
Closed
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
1 change: 1 addition & 0 deletions showcases/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ score_pkg_bundle(
other_package_files = [
"//showcases/standalone:comm_pkg_files",
"//showcases/standalone:kyron_pkg_files",
"//showcases/logging:logging_pkg_files",
"//showcases/orchestration_persistency:orch_per_pkg_files",
"//showcases/simple_lifecycle:simple_lifecycle_pkg_files",
],
Expand Down
37 changes: 37 additions & 0 deletions showcases/logging/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# *******************************************************************************
# 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("//bazel_common:bundlers.bzl", "score_pkg_bundle")

cc_binary(
name = "logging_example",
srcs = ["main.cpp"],
visibility = ["//visibility:public"],
deps = [
"@score_logging//score/mw/log",
"@score_logging//score/mw/log/backend:remote",
],
)

score_pkg_bundle(
name = "logging",
bins = [
":logging_example",
],
config_data = [
"logging.score.json",
],
custom_layout = {
"//showcases/logging:config/logging.json": "etc/logging.json",
},
)
80 changes: 80 additions & 0 deletions showcases/logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Logging Showcase Example

## Overview

This showcase demonstrates the logging capabilities.

A new **Logging example** has been added to the showcase launcher. When running:

```bash
./score_starter
```

select **Logging example** from the menu to start the application.

The example generates log messages with different severity levels and demonstrates both local and remote logging.

---

## What the Example Shows

The application produces logs for the following levels:

- DEBUG
- INFO
- WARN
- ERROR
- FATAL

These logs can be viewed in the console as well as through remote logging tools.

---
## Remote Logging

The example forwards logs through DataRouter.

For remote logging:

- Log messages are sent to the multicast IP address `239.255.42.99` and port configured in `log-channels.json`.
- Select the appropriate network interface depending on the environment where the showcase is running. For example, if running the showcase in a Linux x86 Docker environment, use the Docker network interface
- DataRouter receives the log stream and exposes it through the default DLT port (`3490`).
- Logs can be viewed by connecting DLT Viewer or Chipmunk to the configured DataRouter endpoint.


### DLT Viewer

DLT Viewer Configuration

<img src="images/dlt-viewer.png" alt="DLT Viewer Configuration" width="800">

### Chipmunk

Configure Chipmunk using the same network settings.

<img src="images/chipmunk.png" alt="Chipmunk Configuration" width="800">

Once connected, the incoming log stream can be monitored in real time.

---

## Verification

Verify that:

- The Logging example starts successfully.
- DEBUG messages are received.
- INFO messages are received.
- WARN messages are received.
- ERROR messages are received.
- FATAL messages are received.
- Logs are visible in DLT Viewer.
- Logs are visible in Chipmunk.
- Remote log forwarding through DataRouter is working correctly.

---

## Example Log Output

### Chipmunk Logs

<img src="images/chipmunk-log.png" alt="Chipmunk Logs" width="800">
19 changes: 19 additions & 0 deletions showcases/logging/config/logging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"appId": "LGSC",
"appDesc": "Logging Showcase",

"logMode": "kRemote|kConsole",
"logLevel": "kVerbose",
"logLevelThresholdConsole": "kDebug",

"contextConfigs": [
{
"name": "SENSOR",
"logLevel": "kVerbose"
},
{
"name": "CTRL",
"logLevel": "kInfo"
}
]
}
Binary file added showcases/logging/images/chipmunk-log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added showcases/logging/images/chipmunk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added showcases/logging/images/dlt-viewer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions showcases/logging/logging.score.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Logging example",
"description": "Example for running logging with all log levels via remote and console",
"apps": [
{
"path": "/bin/sh",
"args": [
"-c",
"cd /usr/bin/datarouter && ./datarouter --no_adaptive_runtime >/dev/null 2>&1 &"
],
"env":{}
},
{
"path": "/showcases/bin/logging_example",
"args": [],
"env": {
"MW_LOG_CONFIG_FILE": "/showcases/data/logging/etc/logging.json"
}
}
]
}
153 changes: 153 additions & 0 deletions showcases/logging/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// *******************************************************************************
// Copyright (c) 2026 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
// *******************************************************************************

#include "score/mw/log/logger.h"

#include <chrono>
#include <cstdlib>
#include <iostream>
#include <string_view>
#include <thread>

using namespace std::chrono_literals;

namespace integration
{

namespace config
{
// logging routing contexts
constexpr std::string_view kSensorContext{"SENSOR"};
constexpr std::string_view kControlContext{"CTRL"};
} // namespace config

class SensorPipeline
{
public:
SensorPipeline()
: logger_{score::mw::log::CreateLogger(
config::kSensorContext.data(),
"Sensor")}
{
// log info: sensor service startup
logger_.LogInfo()
<< "sensor initialized";
}

void Process(std::uint32_t frame_id)
{
// log debug: frame entry tracking
logger_.LogDebug()
<< "frame received=" << frame_id;

// log info: frame processed successfully
logger_.LogInfo()
<< "frame processed"
<< " id=" << frame_id;

if (frame_id == 3U)
{
// log warn : processing delay detected
logger_.LogWarn()
<< "processing delay frame=" << frame_id;
}

if (frame_id == 5U)
{
// log error : frame processing failure
logger_.LogError()
<< "processing failed frame=" << frame_id;
}
}

private:
score::mw::log::Logger &logger_;
};

class VehicleController
{
public:
VehicleController()
: logger_{score::mw::log::CreateLogger(
config::kControlContext.data(),
"Control")}
{
// log info : controller initialization complete
logger_.LogInfo()
<< "controller ready mode=AUTO";
}

void Execute(std::uint32_t frame_id)
{
const std::uint32_t speed{frame_id * 10U};

// log debug : control cycle execution trace
logger_.LogDebug()
<< "control cycle=" << frame_id;

// log info : control decision applied
logger_.LogInfo()
<< "control applied"
<< " id=" << frame_id;

if (frame_id >= 6U)
{
// log warn : high speed condition detected
logger_.LogWarn()
<< "high speed frame=" << frame_id;
}

if (frame_id == 7U)
{
// log fatal : emergency stop
logger_.LogFatal()
<< "emergency stop triggered at frame=" << frame_id;
}
}

private:
score::mw::log::Logger &logger_;
};

class Application
{
public:
void Run()
{
std::cout << "\nLogging Example\n";

SensorPipeline sensor;
VehicleController control;

for (std::uint32_t frame{1U}; frame <= 8U; ++frame)
{
std::cout << "Frame=" << frame << '\n';

sensor.Process(frame);
control.Execute(frame);

std::this_thread::sleep_for(300ms);
}

std::cout << "\nLogging Example finished\n";
}
};

} // namespace integration

int main()
{
integration::Application app;
app.Run();
return EXIT_SUCCESS;
}
Loading