diff options
author | Benjamin Barenblat <bbaren@google.com> | 2021-02-04 10:04:07 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2021-02-08 09:32:19 -0500 |
commit | bbec3b57e296543c5005b93ad1d74c6e3ad34a40 (patch) | |
tree | b230fb159a16ef02c0f0c2decfd32ff052d95c18 | |
parent | e3f1c54506041fc65e261cd27d34fb04b44a90c7 (diff) |
Add convenience functions to logging framework
Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
-rw-r--r-- | log.h | 20 | ||||
-rw-r--r-- | log_test.cc | 24 |
2 files changed, 44 insertions, 0 deletions
@@ -61,6 +61,26 @@ class Log final { template <typename... Args> void Message(Level, Args...); + template <typename... Args> + void Debug(Args... args) { + Message(kDebug, args...); + } + + template <typename... Args> + void Info(Args... args) { + Message(kInfo, args...); + } + + template <typename... Args> + void Warning(Args... args) { + Message(kWarning, args...); + } + + template <typename... Args> + 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 |