1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/log_opal_sink.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.2 KiB
C++
Raw Permalink Normal View History

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>
#include <villas/config.hpp>
#include <villas/log.hpp>
2021-02-24 09:17:53 +01:00
#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h>
2021-02-24 09:17:53 +01:00
extern "C" {
/* Define RTLAB before including OpalPrint.h for messages to be sent
* to the OpalDisplay. Otherwise stdout will be used. */
#define RTLAB
#include <OpalPrint.h>
2021-02-24 09:17:53 +01:00
}
namespace villas {
namespace node {
template <typename Mutex>
class OpalSink : public spdlog::sinks::base_sink<Mutex> {
2021-02-24 09:17:53 +01:00
protected:
void sink_it_(const spdlog::details::log_msg &msg) override {
2021-02-24 09:17:53 +01:00
#ifdef WITH_NODE_OPAL
fmt::memory_buffer formatted;
2021-02-24 09:17:53 +01:00
sink::formatter_->format(msg, formatted);
2021-02-24 09:17:53 +01:00
auto str = fmt::to_string(formatted).c_str();
2021-02-24 09:17:53 +01:00
OpalPrint(PROJECT_NAME ": %s\n", str);
2021-02-24 09:17:53 +01:00
#endif
}
2021-02-24 09:17:53 +01: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>;
} // namespace node
} // namespace villas