Boost C++ Libraries: Ticket #12364: In boost::log, how to re-connect to a remote server (like logstash)? https://svn.boost.org/trac10/ticket/12364 <p> By using boost::asio::ip::tcp::iostream and boost::log, I am trying to send log records to a remote server like logstash. But I need to handle the network disconnection/reconnection. Unfortunately, I did not find any way for tcp::iostream. </p> <blockquote> <p> Is it possible to get a notification or exception when the tcp connection is broken? Can I use ip::tcp::socket instead of tcp::iostream in boost::log? Thank you. </p> </blockquote> <p> My code looks like: </p> <pre class="wiki">typedef boost::log::sinks::asynchronous_sink&lt; boost::log::sinks::text_ostream_backend &gt; tcp_sink; boost::shared_ptr&lt; tcp_sink &gt; networkSink; // init tcp stream boost::shared_ptr&lt; sinks::text_ostream_backend &gt; backend = boost::make_shared&lt; sinks::text_ostream_backend &gt;(); boost::shared_ptr&lt; boost::asio::ip::tcp::iostream &gt; stream = boost::make_shared&lt; boost::asio::ip::tcp::iostream &gt;(); stream-&gt;connect("logstash", "1111"); backend-&gt;add_stream(stream); networkSink = boost::make_shared&lt; tcp_sink &gt;(); networkSink-&gt;set_formatter(fmt); networkSink-&gt;set_filter(severity &lt;= severityThreshold); networkSink = boost::make_shared&lt;tcp_sink&gt;(backend ); logging::core::get()-&gt;add_sink(networkSink); </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12364 Trac 1.4.3 Andrey Semashev Sat, 30 Jul 2016 00:47:51 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12364#comment:1 https://svn.boost.org/trac10/ticket/12364#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Boost.Log does not provide a network-based sink out of the box and the closest you can get with the available components is with <code>text_ostream_backend</code> and <code>tcp::iostream</code>. I'm not familiar with <code>tcp::iostream</code> but I suspect the stream obtains bad <code>iostate</code> when the connection is closed. If so, you can unmask exceptions in the stream and then use <a href="http://www.boost.org/doc/libs/1_61_0/libs/log/doc/html/log/detailed/sink_frontends.html#log.detailed.sink_frontends.basic_services.exception_handling">exception handlers</a> to reconnect. Please refer to Boost.ASIO documentation to verify that. </p> <p> You can also implement your own <a href="http://www.boost.org/doc/libs/1_61_0/libs/log/doc/html/log/extension.html#log.extension.sinks.minimalistic_sink_backend">sink backend</a> where you can use the socket directly. </p> Ticket xinyan.zhang@… Tue, 02 Aug 2016 15:46:08 GMT <link>https://svn.boost.org/trac10/ticket/12364#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12364#comment:2</guid> <description> <p> Thank you. I will try. </p> </description> <category>Ticket</category> </item> <item> <author>xinyan.zhang@…</author> <pubDate>Wed, 10 Aug 2016 16:28:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12364#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12364#comment:3</guid> <description> <p> If I implement the TCP reconnect sink backend, can I contribute to boost open source library? Any code standard or coding rule I need to meet? Where shall I put my code? git hub? (I am serious) Thank you. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Wed, 10 Aug 2016 16:57:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12364#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12364#comment:4</guid> <description> <p> The best way to contribute is to create a pull request on <a class="missing wiki">GitHub</a>. The code should meet the common <a href="http://www.boost.org/development/requirements.html#Guidelines">guideleines</a> of Boost and also follow the formatting rules of Boost.Log. Please, don't forget to add tests and documentation. All code/docs must be licensed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>. </p> <p> Note that I'm not promising to accept the pull request - most likely I will have to review it first. But thank you anyway. </p> </description> <category>Ticket</category> </item> </channel> </rss>