Skip to content

Commit 182a4d1

Browse files
committed
ADD: Add batch download logging
1 parent 48b7630 commit 182a4d1

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
### Enhancements
77
- Added `range_by_schema` field to `DatasetRange` struct
8+
- Added logging around `Historical::BatchDownload`
89
- Changed the following Venue, Publisher, and Dataset descriptions:
910
- "ICE Futures Europe (Financials)" renamed to "ICE Europe Financials"
1011
- "ICE Futures Europe (Commodities)" renamed to "ICE Europe Commodities"
1112

13+
### Bug fixes
14+
- Fixed default `ShouldLog` implementation
15+
1216
## 0.38.0 - 2025-06-10
1317

1418
### Enhancements

include/databento/log.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ConsoleLogReceiver : public ILogReceiver {
3737

3838
void Receive(LogLevel level, const std::string& msg) override;
3939
bool ShouldLog(databento::LogLevel level) const override {
40-
return level > min_level_;
40+
return level >= min_level_;
4141
}
4242

4343
private:

src/historical.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "databento/historical.hpp"
22

3-
#include <unordered_map>
4-
5-
#include "databento/publishers.hpp"
6-
73
#ifndef CPPHTTPLIB_OPENSSL_SUPPORT
84
#define CPPHTTPLIB_OPENSSL_SUPPORT
95
#endif
@@ -18,6 +14,7 @@
1814
#include <sstream>
1915
#include <string>
2016
#include <system_error>
17+
#include <unordered_map>
2118
#include <utility> // move
2219

2320
#include "databento/constants.hpp"
@@ -332,25 +329,36 @@ void Historical::StreamToFile(const std::string& url_path,
332329

333330
void Historical::DownloadFile(const std::string& url,
334331
const std::filesystem::path& output_path) {
335-
static const std::string kEndpoint = "Historical::DownloadFile";
332+
static const std::string kMethod = "Historical::DownloadFile";
336333
// extract path from URL
337334
const auto protocol_divider = url.find("://");
338335
std::string path;
336+
339337
if (protocol_divider == std::string::npos) {
340338
const auto slash = url.find_first_of('/');
341339
if (slash == std::string::npos) {
342-
throw InvalidArgumentError{kEndpoint, "url", "No slashes"};
340+
throw InvalidArgumentError{kMethod, "url", "No slashes"};
343341
}
344342
path = url.substr(slash);
345343
} else {
346344
const auto slash = url.find('/', protocol_divider + 3);
347345
if (slash == std::string::npos) {
348-
throw InvalidArgumentError{kEndpoint, "url", "No slashes"};
346+
throw InvalidArgumentError{kMethod, "url", "No slashes"};
349347
}
350348
path = url.substr(slash);
351349
}
350+
std::ostringstream ss;
351+
ss << '[' << kMethod << "] Downloading batch file " << path << " to "
352+
<< output_path;
353+
log_receiver_->Receive(LogLevel::Info, ss.str());
352354

353355
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+
}
354362
}
355363

356364
std::vector<databento::PublisherDetail> Historical::MetadataListPublishers() {

tests/src/log_tests.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <gtest/gtest.h>
1+
#include <gmock/gmock.h>
22

33
#include <sstream>
44
#include <string>
55

66
#include "databento/log.hpp"
7+
#include "gmock/gmock.h"
78

89
namespace databento::tests {
910
class ConsoleLogReceiverTests : public testing::Test {
@@ -24,7 +25,9 @@ TEST_F(ConsoleLogReceiverTests, TestFilter) {
2425
const std::string msg = "Something happened";
2526
target_.Receive(LogLevel::Debug, msg);
2627
const std::string output = stream_.str();
27-
ASSERT_TRUE(output.empty());
28+
EXPECT_TRUE(output.empty());
29+
target_.Receive(LogLevel::Info, msg);
30+
EXPECT_THAT(stream_.str(), testing::HasSubstr(msg));
2831
}
2932

3033
TEST(ILogReceiverTests, TestDefault) {

0 commit comments

Comments
 (0)