Skip to content

Commit

Permalink
feat: changes to logger output
Browse files Browse the repository at this point in the history
  • Loading branch information
aritosteles committed Nov 4, 2024
1 parent 6fb5cbf commit da34d9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/agent/communicator/src/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace communicator
{
constexpr int TOKEN_PRE_EXPIRY_SECS = 2;
constexpr int CONNECTION_RETRY_MSECS = 5000;
constexpr int CONNECTION_RETRY_MSECS = 30000;

Communicator::Communicator(std::unique_ptr<http_client::IHttpClient> httpClient,
std::string uuid,
Expand Down Expand Up @@ -56,10 +56,12 @@ namespace communicator
if (token.has_value())
{
*m_token = token.value();
LogInfo("Successfully authenticated with the manager.");
}
else
{
LogError("Failed to authenticate with the manager.");
LogWarn("Failed to authenticate with the manager. Retrying in {} seconds",
CONNECTION_RETRY_MSECS / 1000); // NOLINT
return boost::beast::http::status::unauthorized;
}

Expand Down
12 changes: 8 additions & 4 deletions src/agent/communicator/src/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ namespace http_client

if (code != boost::system::errc::success)
{
LogError("Connect failed: {}.", code.message());
LogWarn("Failed to send http request. {}. Retrying in {} seconds",
reqParams.Endpoint,
CONNECTION_RETRY_MSECS / 1000); // NOLINT
LogDebug("Http request failed: {} - {}", code.message(), code.what());
socket->Close();
const auto duration = std::chrono::milliseconds(CONNECTION_RETRY_MSECS);
timer.expires_after(duration);
Expand Down Expand Up @@ -187,7 +190,8 @@ namespace http_client
}
catch (std::exception const& e)
{
LogError("Error: {}.", e.what());
LogDebug("Error: {}.", e.what());

res.result(boost::beast::http::status::internal_server_error);
boost::beast::ostream(res.body()) << "Internal server error: " << e.what();
res.prepare_payload();
Expand All @@ -208,7 +212,7 @@ namespace http_client

if (res.result() != boost::beast::http::status::ok)
{
LogError("Error: {}.", res.result_int());
LogDebug("Error: {}.", res.result_int());
return std::nullopt;
}

Expand All @@ -235,7 +239,7 @@ namespace http_client

if (res.result() != boost::beast::http::status::ok)
{
LogError("Error: {}.", res.result_int());
LogDebug("Error: {}.", res.result_int());
return std::nullopt;
}

Expand Down

0 comments on commit da34d9c

Please sign in to comment.