]> git.sesse.net Git - casparcg/blob - core/diagnostics/graph_to_log_sink.cpp
#430 Fixed bug where it was assumed that all Decklink devices implements the IDeckLin...
[casparcg] / core / diagnostics / graph_to_log_sink.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #include "graph_to_log_sink.h"
23
24 #include "call_context.h"
25
26 #include <common/diagnostics/graph.h>
27 #include <common/memory.h>
28 #include <common/log.h>
29
30 #include <tbb/spin_mutex.h>
31
32 namespace caspar { namespace core { namespace diagnostics {
33
34 class graph_to_log_sink : public caspar::diagnostics::spi::graph_sink
35 {
36         tbb::spin_mutex mutex_;
37         std::wstring    text_;
38         std::wstring    context_        = call_context::for_thread().to_string();
39 public:
40         void activate() override
41         {
42         }
43
44         void set_text(const std::wstring& value) override
45         {
46                 tbb::spin_mutex::scoped_lock lock(mutex_);
47                 text_ = value;
48         }
49
50         void set_value(const std::string& name, double value) override
51         {
52         }
53
54         void set_color(const std::string& name, int color) override
55         {
56         }
57
58         void set_tag(caspar::diagnostics::tag_severity severity, const std::string& name) override
59         {
60                 tbb::spin_mutex::scoped_lock lock(mutex_);
61                         
62                 switch (severity)
63                 {
64                 case caspar::diagnostics::tag_severity::INFO:
65                         CASPAR_LOG(trace) << L"[diagnostics] [" << text_ << L"] " << name << L" " << context_;
66                         break;
67                 case caspar::diagnostics::tag_severity::WARNING:
68                         CASPAR_LOG(debug) << L"[diagnostics] [" << text_ << L"] " << name << L" " << context_;
69                         break;
70                 }
71         }
72
73         void auto_reset() override
74         {
75         }
76 };
77
78 void register_graph_to_log_sink()
79 {
80         caspar::diagnostics::spi::register_sink_factory([] { return spl::make_shared<graph_to_log_sink>(); });
81 }
82
83 }}}