|
21 | 21 |
|
22 | 22 | #include <atomic> |
23 | 23 | #include <memory> |
| 24 | +#include <string_view> |
24 | 25 | #include <thread> |
25 | 26 | #include <tuple> |
26 | 27 | #include <vector> |
@@ -429,10 +430,24 @@ TEST(LoggerTest, BuilderDefaultsAndEmitToSink) { |
429 | 430 | EXPECT_NE(records[0].location.line(), 0u); // location defaulted at build site |
430 | 431 | } |
431 | 432 |
|
432 | | -TEST(LoggerTest, BuilderLocationOverride) { |
433 | | - auto loc = std::source_location::current(); |
434 | | - auto record = LogMessage::Builder(LogLevel::kDebug).Location(loc).Build(); |
435 | | - EXPECT_EQ(record.location.line(), loc.line()); |
| 433 | +// location_ is initialized in the Builder constructor, so when Location() is not |
| 434 | +// called the default points at the constructor itself (in logger.h), not at the |
| 435 | +// caller and not at line 0. |
| 436 | +TEST(LoggerTest, BuilderDefaultLocationIsConstructorSite) { |
| 437 | + auto record = LogMessage::Builder(LogLevel::kInfo).Message("m").Build(); |
| 438 | + EXPECT_NE(record.location.line(), 0u); |
| 439 | + EXPECT_NE(std::string_view(record.location.file_name()).find("logger.h"), |
| 440 | + std::string_view::npos); |
| 441 | + EXPECT_NE(std::string_view(record.location.function_name()).find("Builder"), |
| 442 | + std::string_view::npos); |
| 443 | +} |
| 444 | + |
| 445 | +// Location() replaces the constructor default with the caller's site (file + line). |
| 446 | +TEST(LoggerTest, BuilderLocationOverrideUsesCallerSite) { |
| 447 | + auto caller = std::source_location::current(); |
| 448 | + auto record = LogMessage::Builder(LogLevel::kDebug).Location(caller).Build(); |
| 449 | + EXPECT_EQ(record.location.line(), caller.line()); |
| 450 | + EXPECT_STREQ(record.location.file_name(), caller.file_name()); |
436 | 451 | } |
437 | 452 |
|
438 | 453 | } // namespace iceberg |
0 commit comments