|
1 | 1 | #include "databento/historical.hpp" |
2 | 2 |
|
3 | | -#include <unordered_map> |
4 | | - |
5 | | -#include "databento/publishers.hpp" |
6 | | - |
7 | 3 | #ifndef CPPHTTPLIB_OPENSSL_SUPPORT |
8 | 4 | #define CPPHTTPLIB_OPENSSL_SUPPORT |
9 | 5 | #endif |
|
18 | 14 | #include <sstream> |
19 | 15 | #include <string> |
20 | 16 | #include <system_error> |
| 17 | +#include <unordered_map> |
21 | 18 | #include <utility> // move |
22 | 19 |
|
23 | 20 | #include "databento/constants.hpp" |
@@ -332,25 +329,36 @@ void Historical::StreamToFile(const std::string& url_path, |
332 | 329 |
|
333 | 330 | void Historical::DownloadFile(const std::string& url, |
334 | 331 | const std::filesystem::path& output_path) { |
335 | | - static const std::string kEndpoint = "Historical::DownloadFile"; |
| 332 | + static const std::string kMethod = "Historical::DownloadFile"; |
336 | 333 | // extract path from URL |
337 | 334 | const auto protocol_divider = url.find("://"); |
338 | 335 | std::string path; |
| 336 | + |
339 | 337 | if (protocol_divider == std::string::npos) { |
340 | 338 | const auto slash = url.find_first_of('/'); |
341 | 339 | if (slash == std::string::npos) { |
342 | | - throw InvalidArgumentError{kEndpoint, "url", "No slashes"}; |
| 340 | + throw InvalidArgumentError{kMethod, "url", "No slashes"}; |
343 | 341 | } |
344 | 342 | path = url.substr(slash); |
345 | 343 | } else { |
346 | 344 | const auto slash = url.find('/', protocol_divider + 3); |
347 | 345 | if (slash == std::string::npos) { |
348 | | - throw InvalidArgumentError{kEndpoint, "url", "No slashes"}; |
| 346 | + throw InvalidArgumentError{kMethod, "url", "No slashes"}; |
349 | 347 | } |
350 | 348 | path = url.substr(slash); |
351 | 349 | } |
| 350 | + std::ostringstream ss; |
| 351 | + ss << '[' << kMethod << "] Downloading batch file " << path << " to " |
| 352 | + << output_path; |
| 353 | + log_receiver_->Receive(LogLevel::Info, ss.str()); |
352 | 354 |
|
353 | 355 | StreamToFile(path, {}, output_path); |
| 356 | + |
| 357 | + if (log_receiver_->ShouldLog(LogLevel::Debug)) { |
| 358 | + ss.str(""); |
| 359 | + ss << '[' << kMethod << ']' << " Completed download of " << path; |
| 360 | + log_receiver_->Receive(LogLevel::Debug, ss.str()); |
| 361 | + } |
354 | 362 | } |
355 | 363 |
|
356 | 364 | std::vector<databento::PublisherDetail> Historical::MetadataListPublishers() { |
|
0 commit comments