]> git.sesse.net Git - casparcg/blob - common/diagnostics/graph_to_log_sink.cpp
Moved diagnostics warning tags from warning to debug, because they can flood the...
[casparcg] / common / 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 "../log.h"
25
26 #include <tbb/spin_mutex.h>
27
28 namespace caspar { namespace diagnostics {
29
30 class graph_to_log_sink : public spi::graph_sink
31 {
32         tbb::spin_mutex mutex_;
33         std::wstring    text_;
34 public:
35         void activate() override
36         {
37         }
38
39         void set_text(const std::wstring& value) override
40         {
41                 tbb::spin_mutex::scoped_lock lock(mutex_);
42                 text_ = value;
43         }
44
45         void set_value(const std::string& name, double value) override
46         {
47         }
48
49         void set_color(const std::string& name, int color) override
50         {
51         }
52
53         void set_tag(tag_severity severity, const std::string& name) override
54         {
55                 tbb::spin_mutex::scoped_lock lock(mutex_);
56
57                 switch (severity)
58                 {
59                 case tag_severity::INFO:
60                         CASPAR_LOG(trace) << L"[diagnostics] [" << text_ << L"] " << name;
61                         break;
62                 case tag_severity::WARNING:
63                         CASPAR_LOG(debug) << L"[diagnostics] [" << text_ << L"] " << name;
64                         break;
65                 }
66         }
67
68         void auto_reset() override
69         {
70         }
71 };
72
73 void register_graph_to_log_sink()
74 {
75         spi::register_sink_factory([] { return spl::make_shared<graph_to_log_sink>(); });
76 }
77
78 }}