Compare commits

...

2 Commits

Author SHA1 Message Date
Valentin Balaschenko
bf2d64308e clang 2025-05-06 17:28:03 -04:00
Valentin Balaschenko
320d9345d1 transport layer logging 2025-05-06 16:52:09 -04:00
4 changed files with 65 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ target_compile_definitions (opts
BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS
BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
BOOST_CONTAINER_FWD_BAD_DEQUE
BOOST_ASIO_ENABLE_HANDLER_TRACKING
HAS_UNCAUGHT_EXCEPTIONS=1
$<$<BOOL:${boost_show_deprecated}>:
BOOST_ASIO_NO_DEPRECATED

View File

@@ -157,6 +157,48 @@ private:
boost::filesystem::path m_path;
};
class AsioTrackingBuf : public std::streambuf
{
public:
explicit AsioTrackingBuf(beast::Journal j)
{
}
protected:
int
overflow(int ch) override
{
if (ch == '\n')
{
flush();
}
else if (ch != EOF)
{
buffer_ += static_cast<char>(ch);
}
return ch;
}
int
sync() override
{
flush();
return 0;
}
private:
void
flush()
{
if (!buffer_.empty())
{
buffer_.clear();
}
}
std::string buffer_;
};
std::mutex mutable mutex_;
std::map<
std::string,
@@ -166,6 +208,8 @@ private:
beast::severities::Severity thresh_;
File file_;
bool silent_ = false;
std::unique_ptr<AsioTrackingBuf> asioBuf_;
std::unique_ptr<std::ostream> asioStream_;
public:
Logs(beast::severities::Severity level);

View File

@@ -134,6 +134,9 @@ Logs::File::writeln(char const* text)
Logs::Logs(beast::severities::Severity thresh)
: thresh_(thresh) // default severity
{
asioBuf_ = std::make_unique<AsioTrackingBuf>(journal("AsioTracking"));
asioStream_ = std::make_unique<std::ostream>(asioBuf_.get());
std::clog.rdbuf(asioStream_->rdbuf());
}
bool

View File

@@ -580,8 +580,21 @@ PeerImp::close()
{
detaching_ = true; // DEPRECATED
error_code ec;
timer_.cancel(ec);
if (ec)
{
JLOG(journal_.info())
<< "PeerImp::close timer_.cancel ec: " << ec.message();
}
socket_.close(ec);
if (ec)
{
JLOG(journal_.info())
<< "PeerImp::close socket_.close ec: " << ec.message();
}
overlay_.incPeerDisconnect();
if (inbound_)
{
@@ -672,6 +685,10 @@ PeerImp::cancelTimer()
{
error_code ec;
timer_.cancel(ec);
if (ec)
{
JLOG(journal_.info()) << "PeerImp::cancelTimer ec: " << ec.message();
}
}
//------------------------------------------------------------------------------