2021-02-24 09:17:53 +01:00
|
|
|
/* Log sink for OPAL-RTs OpalPrint().
|
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2021-02-24 09:17:53 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/config.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/log.hpp>
|
2021-02-24 09:17:53 +01:00
|
|
|
|
|
|
|
#include <spdlog/details/null_mutex.h>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <spdlog/sinks/base_sink.h>
|
2021-02-24 09:17:53 +01:00
|
|
|
|
|
|
|
extern "C" {
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Define RTLAB before including OpalPrint.h for messages to be sent
|
2024-02-29 21:58:34 +01:00
|
|
|
* to the OpalDisplay. Otherwise stdout will be used. */
|
2023-09-07 11:46:39 +02:00
|
|
|
#define RTLAB
|
|
|
|
#include <OpalPrint.h>
|
2021-02-24 09:17:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
template <typename Mutex>
|
|
|
|
class OpalSink : public spdlog::sinks::base_sink<Mutex> {
|
2021-02-24 09:17:53 +01:00
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
void sink_it_(const spdlog::details::log_msg &msg) override {
|
2021-02-24 09:17:53 +01:00
|
|
|
#ifdef WITH_NODE_OPAL
|
2023-09-07 11:46:39 +02:00
|
|
|
fmt::memory_buffer formatted;
|
2021-02-24 09:17:53 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
sink::formatter_->format(msg, formatted);
|
2021-02-24 09:17:53 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
auto str = fmt::to_string(formatted).c_str();
|
2021-02-24 09:17:53 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
OpalPrint(PROJECT_NAME ": %s\n", str);
|
2021-02-24 09:17:53 +01:00
|
|
|
#endif
|
2023-09-07 11:46:39 +02:00
|
|
|
}
|
2021-02-24 09:17:53 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void flush_() override {
|
|
|
|
// nothing to do
|
|
|
|
}
|
2021-02-24 09:17:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
using OpalSink_mt = OpalSink<std::mutex>;
|
|
|
|
using OpalSink_st = OpalSink<spdlog::details::null_mutex>;
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|