adds close result logging

This commit is contained in:
Peter Thorson
2013-04-20 08:34:28 -05:00
parent ea3426868c
commit 72b5fada72
2 changed files with 24 additions and 0 deletions

View File

@@ -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;

View File

@@ -1296,7 +1296,10 @@ void connection<config>::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<config>::log_open_result()
m_alog.write(log::alevel::connect,s.str());
}
template <typename config>
void connection<config>::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