}
}
+std::shared_ptr<void> add_preformatted_line_sink(std::function<void(std::string line)> formatted_line_sink)
+{
+ class sink_backend : public boost::log::sinks::basic_formatted_sink_backend<char>
+ {
+ std::function<void(std::string line)> formatted_line_sink_;
+ public:
+ sink_backend(std::function<void(std::string line)> formatted_line_sink)
+ : formatted_line_sink_(std::move(formatted_line_sink))
+ {
+ }
+
+ void consume(const boost::log::record_view& rec, const std::string& formatted_message)
+ {
+ try
+ {
+ formatted_line_sink_(formatted_message);
+ }
+ catch (...)
+ {
+ std::cerr << "[sink_backend] Error while consuming formatted message: " << formatted_message << std::endl << std::endl;
+ }
+ }
+ };
+
+ typedef boost::log::sinks::synchronous_sink<sink_backend> sink_type;
+
+ auto sink = boost::make_shared<sink_type>(std::move(formatted_line_sink));
+ bool print_all_characters = true;
+
+ sink->set_formatter(boost::bind(&my_formatter<boost::log::formatting_ostream>, print_all_characters, _1, _2));
+
+ boost::log::core::get()->add_sink(sink);
+
+ return std::shared_ptr<void>(nullptr, [=](void*)
+ {
+ boost::log::core::get()->remove_sink(sink);
+ });
+}
+
void set_log_level(const std::wstring& lvl)
{
if (boost::iequals(lvl, L"trace"))
#include <string>
#include <locale>
+#include <functional>
+#include <memory>
namespace caspar { namespace log {
}
void add_file_sink(const std::wstring& folder);
+std::shared_ptr<void> add_preformatted_line_sink(std::function<void(std::string line)> formatted_line_sink);
typedef boost::log::sources::wseverity_logger_mt<boost::log::trivial::severity_level> caspar_logger;
clk/clk_commands.cpp
clk/clk_command_processor.cpp
+ log/tcp_logger_protocol_strategy.cpp
+
osc/oscpack/OscOutboundPacketStream.cpp
osc/oscpack/OscPrintReceivedElements.cpp
osc/oscpack/OscReceivedElements.cpp
clk/clk_commands.h
clk/clk_command_processor.h
+ log/tcp_logger_protocol_strategy.h
+
osc/oscpack/MessageMappingOscPacketListener.h
osc/oscpack/OscException.h
osc/oscpack/OscHostEndianness.h
source_group(sources\\amcp amcp/*)
source_group(sources\\cii cii/*)
source_group(sources\\clk clk/*)
+source_group(sources\\log log/*)
source_group(sources\\osc\\oscpack osc/oscpack/*)
source_group(sources\\osc osc/*)
source_group(sources\\util util/*)
--- /dev/null
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Helge Norberg, helge.norberg@svt.se
+*/
+
+#include "../StdAfx.h"
+
+#include "tcp_logger_protocol_strategy.h"
+
+#include <common/log.h>
+
+namespace caspar { namespace protocol { namespace log {
+
+class tcp_logger_protocol_strategy : public IO::protocol_strategy<char>
+{
+ spl::shared_ptr<IO::client_connection<char>> client_connection_;
+ std::shared_ptr<void> log_sink_ = caspar::log::add_preformatted_line_sink([=](std::string line)
+ {
+ handle_log_line(std::move(line));
+ });
+public:
+ tcp_logger_protocol_strategy(spl::shared_ptr<IO::client_connection<char>> client_connection)
+ : client_connection_(std::move(client_connection))
+ {
+ }
+
+ void handle_log_line(std::string line)
+ {
+ line += "\r\n";
+ client_connection_->send(std::move(line));
+ }
+
+ void parse(const std::string& data) override
+ {
+ }
+};
+
+spl::shared_ptr<IO::protocol_strategy<char>> tcp_logger_protocol_strategy_factory::create(
+ const spl::shared_ptr<IO::client_connection<char>>& client_connection)
+{
+ return spl::make_shared<tcp_logger_protocol_strategy>(client_connection);
+}
+
+}}}
--- /dev/null
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Helge Norberg, helge.norberg@svt.se
+*/
+
+#pragma once
+
+#include "../util/protocol_strategy.h"
+
+namespace caspar { namespace protocol { namespace log {
+
+struct tcp_logger_protocol_strategy_factory : public IO::protocol_strategy_factory<char>
+{
+ spl::shared_ptr<IO::protocol_strategy<char>> create(
+ const spl::shared_ptr<IO::client_connection<char>>& client_connection) override;
+};
+
+}}}
<port>5250</port>\r
<protocol>AMCP</protocol>\r
</tcp>\r
+ <tcp>\r
+ <port>3250</port>\r
+ <protocol>LOG</protocol>\r
+ </tcp>\r
</controllers>\r
</configuration>\r
\r
#include <protocol/util/AsyncEventServer.h>
#include <protocol/util/strategy_adapters.h>
#include <protocol/osc/client.h>
+#include <protocol/log/tcp_logger_protocol_strategy.h>
#include <boost/algorithm/string.hpp>
#include <boost/thread.hpp>
return spl::make_shared<to_unicode_adapter_factory>(
"ISO-8859-1",
spl::make_shared<CLK::clk_protocol_strategy_factory>(channels_, cg_registry_, producer_registry_));
-
+ else if (boost::iequals(name, L"LOG"))
+ return spl::make_shared<protocol::log::tcp_logger_protocol_strategy_factory>();
+
CASPAR_THROW_EXCEPTION(caspar_exception() << arg_name_info(L"name") << arg_value_info(name) << msg_info(L"Invalid protocol"));
}