Skip to content

Commit 2d8b992

Browse files
Accept string view as extra param inline (motis-project#36)
* log: adding support for passing string_view inline * logging: use perfect forwarding * formatting --------- Co-authored-by: Lucas Cimon <[email protected]>
1 parent ecd49ba commit 2d8b992

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.pkg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[fmt]
1010
[email protected]:motis-project/fmt.git
1111
branch=master
12-
commit=edb385ac526c24bc917ec4a41bb0edb28f0ca59e
12+
commit=dc10f83be70ac2873d5f8d1ce317596f1fd318a2
1313
[cista]
1414
[email protected]:felixguendling/cista.git
1515
branch=master

include/utl/logging.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ inline std::string now() {
4848
/// Produce a new log line at the given `level`.
4949
template <log_level LogLevel, typename... Args>
5050
struct log {
51-
log(const char* ctx, fmt::format_string<Args...> fmt_str,
52-
const Args&&... args,
51+
log(const char* ctx, fmt::format_string<Args...> fmt_str, Args&&... args,
5352
std::source_location const& loc = std::source_location::current())
5453
: loc_{loc},
5554
ctx_{ctx},

test/logging_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ TEST(log, accept_string_view_as_extra_param) {
5252
"Hello world!\n"));
5353
};
5454

55+
TEST(log, accept_string_view_as_extra_param_inline) {
56+
testing::internal::CaptureStderr();
57+
std::string str{"world"};
58+
utl::log_info("MyCtx", "Hello {}!", std::string_view{str});
59+
EXPECT_THAT(testing::internal::GetCapturedStderr(),
60+
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] "
61+
"Hello world!\n"));
62+
};
63+
5564
TEST(log, can_have_optional_attrs) {
5665
testing::internal::CaptureStderr();
5766
utl::log_info("MyCtx", "Message").attrs({{"key", "value"}});

0 commit comments

Comments
 (0)