0.2.0
Loading...
Searching...
No Matches
dist_filter_sink.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include "spdlog/sinks/dist_sink.h"
17#include <regex>
18
19namespace spdlog::sinks
20{
21
23template<typename Mutex>
24class dist_filter_sink : public spdlog::sinks::dist_sink<Mutex> // NOLINT(cppcoreguidelines-virtual-class-destructor)
25{
26 public:
29 explicit dist_filter_sink(const std::string& filter)
30 : filter_(filter, std::regex_constants::ECMAScript){};
32 ~dist_filter_sink() override = default;
36 dist_filter_sink(dist_filter_sink&&) noexcept = default;
38 dist_filter_sink& operator=(const dist_filter_sink&) = delete;
40 dist_filter_sink& operator=(dist_filter_sink&&) noexcept = default;
41
42 protected:
44 std::regex filter_;
45
48 void sink_it_(const spdlog::details::log_msg& msg) override
49 {
50 spdlog::memory_buf_t formatted_buf;
51 spdlog::sinks::base_sink<Mutex>::formatter_->format(msg, formatted_buf);
52 std::string formatted = fmt::to_string(formatted_buf);
53
54 if (std::regex_search(formatted, filter_))
55 {
56 spdlog::sinks::dist_sink<Mutex>::sink_it_(msg);
57 }
58 }
59};
60
61#ifndef DOXYGEN_IGNORE
62
63 #include "spdlog/details/null_mutex.h"
64 #include <mutex>
65using dist_filter_sink_mt = dist_filter_sink<std::mutex>;
66using dist_filter_sink_st = dist_filter_sink<spdlog::details::null_mutex>;
67
68#endif
69
70} // namespace spdlog::sinks
Distribution sink (mux) with filter option.
Definition dist_filter_sink.hpp:25
std::regex filter_
String to filter messages for.
Definition dist_filter_sink.hpp:44
dist_filter_sink(dist_filter_sink &&) noexcept=default
Move constructor.
dist_filter_sink(const std::string &filter)
Default constructor.
Definition dist_filter_sink.hpp:29
~dist_filter_sink() override=default
Destructor.
void sink_it_(const spdlog::details::log_msg &msg) override
Function called to process the log message.
Definition dist_filter_sink.hpp:48
dist_filter_sink(const dist_filter_sink &)=delete
Copy constructor.