Skip to content

Commit 70e2519

Browse files
Add network verbose log output to file
Fix the CURLOPT_NOSIGNAL option is not set after reset Relates-To: OCMAM-418 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 94e6d9d commit 70e2519

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

olp-cpp-sdk-core/include/olp/core/http/NetworkInitializationSettings.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 HERE Europe B.V.
2+
* Copyright (C) 2023-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,8 +19,10 @@
1919

2020
#pragma once
2121

22-
#include "olp/core/CoreApi.h"
23-
#include "olp/core/http/CertificateSettings.h"
22+
#include <boost/optional/optional.hpp>
23+
24+
#include <olp/core/CoreApi.h>
25+
#include <olp/core/http/CertificateSettings.h>
2426

2527
namespace olp {
2628
namespace http {
@@ -38,6 +40,12 @@ struct CORE_API NetworkInitializationSettings {
3840
* @brief The custom certificate settings.
3941
*/
4042
CertificateSettings certificate_settings;
43+
44+
/**
45+
* @brief Enable the underlying implementation to produce additional logs.
46+
* Note: This is EXPERIMENTAL settings, only CURL implementation supports it.
47+
*/
48+
boost::optional<std::string> log_file_path;
4149
};
4250

4351
} // namespace http

olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -296,7 +296,8 @@ NetworkCurl::NetworkCurl(NetworkInitializationSettings settings)
296296
: handles_(settings.max_requests_count),
297297
static_handle_count_(
298298
std::max(static_cast<size_t>(1u), settings.max_requests_count / 4u)),
299-
certificate_settings_(std::move(settings.certificate_settings)) {
299+
certificate_settings_(std::move(settings.certificate_settings)),
300+
curl_log_path_(settings.log_file_path) {
300301
OLP_SDK_LOG_TRACE(kLogTag, "Created NetworkCurl with address="
301302
<< this << ", handles_count="
302303
<< settings.max_requests_count);
@@ -307,6 +308,17 @@ NetworkCurl::NetworkCurl(NetworkInitializationSettings settings)
307308
static_cast<int>(error));
308309
}
309310

311+
if (curl_log_path_) {
312+
auto err = fopen_s(&stderr_, curl_log_path_->c_str(), "w+");
313+
if ( err != 0 ) {
314+
OLP_SDK_LOG_ERROR(
315+
kLogTag, "Failed to init curl logging, error: " << err);
316+
} else {
317+
OLP_SDK_LOG_INFO_F(kLogTag, "Curl logs enabled to file: %s",
318+
curl_log_path_->c_str());
319+
}
320+
}
321+
310322
#ifdef OLP_SDK_CURL_HAS_SUPPORT_SSL_BLOBS
311323
SetupCertificateBlobs();
312324
#else
@@ -609,11 +621,11 @@ ErrorCode NetworkCurl::SendImplementation(
609621

610622
CURL* curl_handle = handle->handle;
611623

612-
if (verbose_) {
624+
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1L);
625+
626+
if (stderr_ != nullptr) {
613627
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
614-
if (stderr_ != nullptr) {
615-
curl_easy_setopt(curl_handle, CURLOPT_STDERR, stderr_);
616-
}
628+
curl_easy_setopt(curl_handle, CURLOPT_STDERR, stderr_);
617629
} else {
618630
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 0L);
619631
}
@@ -830,7 +842,6 @@ NetworkCurl::RequestHandle* NetworkCurl::GetHandle(
830842
"GetHandle - curl_easy_init failed, id=" << id);
831843
return nullptr;
832844
}
833-
curl_easy_setopt(handle.handle, CURLOPT_NOSIGNAL, 1L);
834845
}
835846
handle.in_use = true;
836847
handle.callback = std::move(callback);

olp-cpp-sdk-core/src/http/curl/NetworkCurl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -392,6 +392,9 @@ class NetworkCurl : public olp::http::Network,
392392
/// blobs so cURL does not need to copy them.
393393
CertificateSettings certificate_settings_;
394394

395+
/// The path to store CURL logs
396+
boost::optional<std::string> curl_log_path_;
397+
395398
#ifdef OLP_SDK_CURL_HAS_SUPPORT_SSL_BLOBS
396399
/// SSL certificate blobs.
397400
boost::optional<SslCertificateBlobs> ssl_certificates_blobs_;

0 commit comments

Comments
 (0)