aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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