From bbec3b57e296543c5005b93ad1d74c6e3ad34a40 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Thu, 4 Feb 2021 10:04:07 -0500 Subject: Add convenience functions to logging framework Reviewed-by: Alex Chernyakhovsky --- log.h | 20 ++++++++++++++++++++ log_test.cc | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/log.h b/log.h index fe2015b..e0d3963 100644 --- a/log.h +++ b/log.h @@ -61,6 +61,26 @@ class Log final { template void Message(Level, Args...); + template + void Debug(Args... args) { + Message(kDebug, args...); + } + + template + void Info(Args... args) { + Message(kInfo, args...); + } + + template + void Warning(Args... args) { + Message(kWarning, args...); + } + + template + void Error(Args... args) { + Message(kError, args...); + } + private: std::string prefix_; Level minimum_level_; diff --git a/log_test.cc b/log_test.cc index cec1199..0ceb3f2 100644 --- a/log_test.cc +++ b/log_test.cc @@ -56,5 +56,29 @@ TEST(LogTest, HidesUninterestingMessages) { EXPECT_THAT(s.str(), IsEmpty()); } +TEST(LogTest, DedicatedDebugFunction) { + std::ostringstream s; + Log("program", Log::kDebug, s).Debug("message"); + EXPECT_THAT(s.str(), HasSubstr("debug:")); +} + +TEST(LogTest, DedicatedInfoFunction) { + std::ostringstream s; + Log("program", s).Info("message"); + EXPECT_EQ(s.str(), "program: message\n"); +} + +TEST(LogTest, DedicatedWarningFunction) { + std::ostringstream s; + Log("program", s).Warning("message"); + EXPECT_THAT(s.str(), HasSubstr("warning:")); +} + +TEST(LogTest, DedicatedErrorFunction) { + std::ostringstream s; + Log("program", s).Error("message"); + EXPECT_THAT(s.str(), HasSubstr("error:")); +} + } // namespace } // namespace gsrsup -- cgit v1.2.3