Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
dist_sink.h
Go to the documentation of this file.
1//
2// Copyright (c) 2015 David Schury, Gabi Melman
3// Distributed under the MIT License (http://opensource.org/licenses/MIT)
4//
5
6#pragma once
7
8#include "../details/log_msg.h"
9#include "../details/null_mutex.h"
10#include "base_sink.h"
11#include "sink.h"
12
13#include <algorithm>
14#include <mutex>
15#include <memory>
16#include <vector>
17
18// Distribution sink (mux). Stores a vector of sinks which get called when log is called
19
20namespace spdlog
21{
22namespace sinks
23{
24template<class Mutex>
25class dist_sink: public base_sink<Mutex>
26{
27public:
28 explicit dist_sink() :_sinks() {}
29 dist_sink(const dist_sink&) = delete;
30 dist_sink& operator=(const dist_sink&) = delete;
31 virtual ~dist_sink() = default;
32
33protected:
34 std::vector<std::shared_ptr<sink>> _sinks;
35
36 void _sink_it(const details::log_msg& msg) override
37 {
38 for (auto &sink : _sinks)
39 {
40 if( sink->should_log( msg.level))
41 {
42 sink->log(msg);
43 }
44 }
45 }
46
47 void _flush() override
48 {
49 for (auto &sink : _sinks)
50 sink->flush();
51 }
52
53public:
54
55
56 void add_sink(std::shared_ptr<sink> sink)
57 {
60 }
61
62 void remove_sink(std::shared_ptr<sink> sink)
63 {
66 }
67};
68
69typedef dist_sink<std::mutex> dist_sink_mt;
71}
72}
std::vector< std::shared_ptr< sink > > _sinks
Definition dist_sink.h:34
void _sink_it(const details::log_msg &msg) override
Definition dist_sink.h:36
void remove_sink(std::shared_ptr< sink > sink)
Definition dist_sink.h:62
dist_sink & operator=(const dist_sink &)=delete
void add_sink(std::shared_ptr< sink > sink)
Definition dist_sink.h:56
void _flush() override
Definition dist_sink.h:47
virtual ~dist_sink()=default
dist_sink(const dist_sink &)=delete
dist_sink< std::mutex > dist_sink_mt
Definition dist_sink.h:69
dist_sink< details::null_mutex > dist_sink_st
Definition dist_sink.h:70
Definition json.hpp:4518