in cloudwatch_logs_common/src/log_publisher.cpp [184:227]
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors LogPublisher::SendLogs(Aws::String & next_token, LogCollection & data) {
AWS_LOG_DEBUG(__func__,
"Attempting to use logs of size %i", data.size());
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors send_logs_status = CW_LOGS_FAILED;
if (!data.empty()) {
int tries = kMaxRetries;
while (CW_LOGS_SUCCEEDED != send_logs_status && tries > 0) {
AWS_LOG_INFO(__func__, "Sending logs to CW");
if (!std::ifstream("/tmp/internet").good()) {
send_logs_status = this->cloudwatch_facade_->SendLogsToCloudWatch(
next_token, this->log_group_, this->log_stream_, data);
AWS_LOG_DEBUG(__func__, "SendLogs status=%d", send_logs_status);
}
if (CW_LOGS_SUCCEEDED != send_logs_status) {
AWS_LOG_WARN(__func__, "Unable to send logs to CloudWatch, retrying ...");
Aws::CloudWatchLogs::ROSCloudWatchLogsErrors get_token_status =
this->cloudwatch_facade_->GetLogStreamToken(this->log_group_, this->log_stream_,
next_token);
if (CW_LOGS_SUCCEEDED != get_token_status) {
AWS_LOG_WARN(__func__,
"Unable to obtain the sequence token to use");
break;
}
}
tries--;
}
if (CW_LOGS_SUCCEEDED != send_logs_status) {
AWS_LOG_WARN(
__func__,
"Unable to send logs to CloudWatch");
}
} else {
AWS_LOG_DEBUG(__func__,
"Unable to obtain the sequence token to use");
}
checkIfConnected(send_logs_status); // mark offline if needed
return send_logs_status;
}