diff --git a/websocketpp/connection.hpp b/websocketpp/connection.hpp index fbf70f1f36..afe14abf3d 100644 --- a/websocketpp/connection.hpp +++ b/websocketpp/connection.hpp @@ -960,6 +960,13 @@ private: */ void log_open_result(); + /// Prints information about a connection being closed to the access log + /** + * Prints information about a connection being closed to the access log. + * Includes: local and remote close codes and reasons + */ + void log_close_result(); + // static settings const std::string m_user_agent; diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index 34cb0271bf..48e702b31a 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -1296,7 +1296,10 @@ void connection::terminate() { } } else { m_alog.write(log::alevel::devel,"terminate called on connection that was already terminated"); + return; } + + log_close_result(); } catch (const std::exception& e) { m_elog.write(log::elevel::warn, std::string("terminate failed. Reason was: ") + e.what()); @@ -1765,6 +1768,20 @@ void connection::log_open_result() m_alog.write(log::alevel::connect,s.str()); } +template +void connection::log_close_result() +{ + std::stringstream s; + + s << "Disconnect " + << "close local:[" << m_local_close_code + << (m_local_close_reason == "" ? "" : ","+m_local_close_reason) + << "] remote:[" << m_remote_close_code + << (m_remote_close_reason == "" ? "" : ","+m_remote_close_reason) << "]"; + + m_alog.write(log::alevel::disconnect,s.str()); +} + } // namespace websocketpp #endif // WEBSOCKETPP_CONNECTION_IMPL_HPP