~singpolyma/biboumi

f9c31cb129b17d57281c87b549b382957dca425e — louiz’ 7 years ago 4cc3dc0
The logger writes to std::clog
2 files changed, 5 insertions(+), 5 deletions(-)

M louloulibs/logger/logger.cpp
M tests/logger.cpp
M louloulibs/logger/logger.cpp => louloulibs/logger/logger.cpp +1 -1
@@ 3,7 3,7 @@

Logger::Logger(const int log_level):
  log_level(log_level),
  stream(std::cout.rdbuf()),
  stream(std::clog.rdbuf()),
  null_buffer{},
  null_stream{&null_buffer}
{

M tests/logger.cpp => tests/logger.cpp +4 -4
@@ 23,14 23,14 @@ TEST_CASE("Basic logging")
      Config::set("log_level", "0");
      WHEN("we log some debug text")
        {
          IoTester<std::ostream> out(std::cout);
          IoTester<std::ostream> out(std::clog);
          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);
          IoTester<std::ostream> out(std::clog);
          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");


@@ 41,14 41,14 @@ TEST_CASE("Basic logging")
      Config::set("log_level", "3");
      WHEN("we log some debug text")
        {
          IoTester<std::ostream> out(std::cout);
          IoTester<std::ostream> out(std::clog);
          log_debug(123, "debug");
          THEN("nothing is written")
            CHECK(out.str().empty());
        }
      WHEN("we log some errors")
        {
          IoTester<std::ostream> out(std::cout);
          IoTester<std::ostream> out(std::clog);
          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");