Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log: removing 'fn' from log line format #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions include/utl/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ struct log {
? strrchr(loc_.file_name(), '/') + 1
: loc_.file_name();
#endif
fmt::print(
std::clog, "{time} [{level}] [{file}:{line} {fn}] [{ctx}] {msg}\n",
fmt::arg("time", now()), fmt::arg("level", to_str(LogLevel)),
fmt::arg("file", base_file_name), fmt::arg("line", loc_.line()),
fmt::arg("fn", loc_.function_name()), fmt::arg("ctx", ctx_),
fmt::arg("msg", msg_));
fmt::print(std::clog, "{time} [{level}] [{file}:{line}] [{ctx}] {msg}\n",
fmt::arg("time", now()), fmt::arg("level", to_str(LogLevel)),
fmt::arg("file", base_file_name),
fmt::arg("line", loc_.line()), fmt::arg("ctx", ctx_),
fmt::arg("msg", msg_));
}
}

Expand Down
28 changes: 12 additions & 16 deletions test/logging_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TEST(log, can_send_info_msg) {
EXPECT_THAT(
testing::internal::GetCapturedStderr(),
MatchesRegex(
".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] Message\n"));
".+T.+Z \\[info\\] \\[logging.+:..\\] \\[MyCtx\\] Message\n"));
}

TEST(log, can_send_debug_msg) {
Expand All @@ -22,7 +22,7 @@ TEST(log, can_send_debug_msg) {
EXPECT_THAT(
testing::internal::GetCapturedStderr(),
MatchesRegex(
".+T.+Z \\[debug\\] \\[logging.+:.+\\] \\[MyCtx\\] Message\n"));
".+T.+Z \\[debug\\] \\[logging.+:..\\] \\[MyCtx\\] Message\n"));
}

TEST(log, can_send_error_msg) {
Expand All @@ -31,15 +31,15 @@ TEST(log, can_send_error_msg) {
EXPECT_THAT(
testing::internal::GetCapturedStderr(),
MatchesRegex(
".+T.+Z \\[error\\] \\[logging.+:.+\\] \\[MyCtx\\] Message\n"));
".+T.+Z \\[error\\] \\[logging.+:..\\] \\[MyCtx\\] Message\n"));
}

TEST(log, can_format_extra_params) {
testing::internal::CaptureStderr();
auto const value = 42;
utl::log_info("MyCtx", "String={} Int={}", "Hello", value);
EXPECT_THAT(testing::internal::GetCapturedStderr(),
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] "
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:..\\] \\[MyCtx\\] "
"String=Hello Int=42\n"));
}

Expand All @@ -48,7 +48,7 @@ TEST(log, accept_string_view_as_extra_param) {
std::string_view str{"world"};
utl::log_info("MyCtx", "Hello {}!", str);
EXPECT_THAT(testing::internal::GetCapturedStderr(),
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] "
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:..\\] \\[MyCtx\\] "
"Hello world!\n"));
}

Expand All @@ -57,7 +57,7 @@ TEST(log, accept_string_view_as_extra_param_inline) {
std::string str{"world"};
utl::log_info("MyCtx", "Hello {}!", std::string_view{str});
EXPECT_THAT(testing::internal::GetCapturedStderr(),
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] "
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:..\\] \\[MyCtx\\] "
"Hello world!\n"));
}

Expand All @@ -67,25 +67,21 @@ TEST(log, can_have_optional_attrs) {
EXPECT_THAT(
testing::internal::GetCapturedStderr(),
MatchesRegex(
".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] Message\n"));
".+T.+Z \\[info\\] \\[logging.+:..\\] \\[MyCtx\\] Message\n"));
}


struct dtor {
friend std::ostream& operator<<(std::ostream& out, dtor const& x) {
return out << x.x_;
}
~dtor() { std::clog << "DESTROY\n";}
~dtor() { std::clog << "DESTROY\n"; }
int x_;
};
TEST(log, temporary_streamed) {
testing::internal::CaptureStderr();
auto const tmp = []() {
return dtor{.x_ = 9999};
};
auto const tmp = []() { return dtor{.x_ = 9999}; };
utl::log_info("MyCtx", "{} {}", fmt::streamed(tmp()), fmt::streamed(tmp()));
EXPECT_THAT(
testing::internal::GetCapturedStderr(),
MatchesRegex(
".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] 9999 9999\nDESTROY\nDESTROY\n"));
EXPECT_THAT(testing::internal::GetCapturedStderr(),
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:..\\] \\[MyCtx\\] "
"9999 9999\nDESTROY\nDESTROY\n"));
}
Loading