aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2021-02-04 10:04:07 -0500
committerGravatar Benjamin Barenblat <bbaren@google.com>2021-02-08 09:32:19 -0500
commitbbec3b57e296543c5005b93ad1d74c6e3ad34a40 (patch)
treeb230fb159a16ef02c0f0c2decfd32ff052d95c18
parente3f1c54506041fc65e261cd27d34fb04b44a90c7 (diff)
Add convenience functions to logging framework
Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
-rw-r--r--log.h20
-rw-r--r--log_test.cc24
2 files changed, 44 insertions, 0 deletions
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 <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