summaryrefslogtreecommitdiff
path: root/tests/logger.cpp
diff options
context:
space:
mode:
authorVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:41 +0530
committerVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:41 +0530
commit4e4de7284e6e4d89d182ea459823bbec1e408842 (patch)
tree47e0ed5216b48649b138f168f61fddca2b0c076a /tests/logger.cpp
parentdfb3a6edfacf2f16a8a63690b3e8058b6295d1a3 (diff)
parenteda4b75b1cff83336e87da90efca9fd6b4ced2c7 (diff)
downloadbiboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.gz
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.bz2
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.xz
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.zip
Updated version 3.0 from 'upstream/3.0'
with Debian dir 0f18938e98f5a466f36719f60cef0490163ab845
Diffstat (limited to 'tests/logger.cpp')
-rw-r--r--tests/logger.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/logger.cpp b/tests/logger.cpp
new file mode 100644
index 0000000..1d59a22
--- /dev/null
+++ b/tests/logger.cpp
@@ -0,0 +1,57 @@
+#include "catch.hpp"
+
+#include <logger/logger.hpp>
+#include <config/config.hpp>
+
+#include "io_tester.hpp"
+#include <iostream>
+
+using namespace std::string_literals;
+
+TEST_CASE("Basic logging")
+{
+#ifdef SYSTEMD_FOUND
+ const std::string debug_header = "<7>";
+ const std::string error_header = "<3>";
+#else
+ const std::string debug_header = "[DEBUG]: ";
+ const std::string error_header = "[ERROR]: ";
+#endif
+ Logger::instance().reset();
+ GIVEN("A logger with log_level 0")
+ {
+ Config::set("log_level", "0");
+ WHEN("we log some debug text")
+ {
+ IoTester<std::ostream> out(std::cout);
+ log_debug("deb", "ug");
+ THEN("debug logs are written")
+ CHECK(out.str() == debug_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\tdebug\n");
+ }
+ WHEN("we log some errors")
+ {
+ IoTester<std::ostream> out(std::cout);
+ log_error("err", 12, "or");
+ THEN("error logs are written")
+ CHECK(out.str() == error_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terr12or\n");
+ }
+ }
+ GIVEN("A logger with log_level 3")
+ {
+ Config::set("log_level", "3");
+ WHEN("we log some debug text")
+ {
+ IoTester<std::ostream> out(std::cout);
+ log_debug(123, "debug");
+ THEN("nothing is written")
+ CHECK(out.str().empty());
+ }
+ WHEN("we log some errors")
+ {
+ IoTester<std::ostream> out(std::cout);
+ log_error(123, " errors");
+ THEN("error logs are still written")
+ CHECK(out.str() == error_header + "tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\t123 errors\n");
+ }
+ }
+}