allow printf style logging
* tests updated for printf style * tests makefile support printf style
This commit is contained in:
		@@ -12,9 +12,13 @@ TEST_CASE("simple_file_logger", "[simple_logger]]")
 | 
			
		||||
    auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename);
 | 
			
		||||
    logger->set_pattern("%v");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if !defined(SPDLOG_FMT_PRINTF)
 | 
			
		||||
    logger->info("Test message {}", 1);
 | 
			
		||||
    logger->info("Test message {}", 2);
 | 
			
		||||
#else
 | 
			
		||||
    logger->info("Test message %d", 1);
 | 
			
		||||
    logger->info("Test message %d", 2);
 | 
			
		||||
#endif
 | 
			
		||||
    logger->flush();
 | 
			
		||||
    REQUIRE(file_contents(filename) == std::string("Test message 1\nTest message 2\n"));
 | 
			
		||||
    REQUIRE(count_lines(filename) == 2);
 | 
			
		||||
@@ -33,8 +37,13 @@ TEST_CASE("flush_on", "[flush_on]]")
 | 
			
		||||
    logger->trace("Should not be flushed");
 | 
			
		||||
    REQUIRE(count_lines(filename) == 0);
 | 
			
		||||
 | 
			
		||||
#if !defined(SPDLOG_FMT_PRINTF)
 | 
			
		||||
    logger->info("Test message {}", 1);
 | 
			
		||||
    logger->info("Test message {}", 2);
 | 
			
		||||
#else
 | 
			
		||||
    logger->info("Test message %d", 1);
 | 
			
		||||
    logger->info("Test message %d", 2);
 | 
			
		||||
#endif
 | 
			
		||||
    logger->flush();
 | 
			
		||||
    REQUIRE(file_contents(filename) == std::string("Should not be flushed\nTest message 1\nTest message 2\n"));
 | 
			
		||||
    REQUIRE(count_lines(filename) == 3);
 | 
			
		||||
@@ -47,7 +56,13 @@ TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
 | 
			
		||||
    auto logger = spdlog::rotating_logger_mt("logger", basename, 1024, 0);
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < 10; ++i)
 | 
			
		||||
    {
 | 
			
		||||
#if !defined(SPDLOG_FMT_PRINTF)
 | 
			
		||||
        logger->info("Test message {}", i);
 | 
			
		||||
#else
 | 
			
		||||
        logger->info("Test message %d", i);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    logger->flush();
 | 
			
		||||
    auto filename = basename;
 | 
			
		||||
@@ -67,7 +82,13 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
 | 
			
		||||
    auto filename = basename;
 | 
			
		||||
    REQUIRE(count_lines(filename) == 10);
 | 
			
		||||
    for (int i = 0; i < 1000; i++)
 | 
			
		||||
    {
 | 
			
		||||
#if !defined(SPDLOG_FMT_PRINTF)
 | 
			
		||||
        logger->info("Test message {}", i);
 | 
			
		||||
#else
 | 
			
		||||
        logger->info("Test message %d", i);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    logger->flush();
 | 
			
		||||
    REQUIRE(get_filesize(filename) <= 1024);
 | 
			
		||||
@@ -88,7 +109,13 @@ TEST_CASE("daily_logger", "[daily_logger]]")
 | 
			
		||||
    auto logger = spdlog::daily_logger_mt("logger", basename, 0, 0);
 | 
			
		||||
    logger->flush_on(spdlog::level::info);
 | 
			
		||||
    for (int i = 0; i < 10; ++i)
 | 
			
		||||
    {
 | 
			
		||||
#if !defined(SPDLOG_FMT_PRINTF)
 | 
			
		||||
        logger->info("Test message {}", i);
 | 
			
		||||
#else
 | 
			
		||||
        logger->info("Test message %d", i);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto filename = w.str();
 | 
			
		||||
    REQUIRE(count_lines(filename) == 10);
 | 
			
		||||
@@ -110,7 +137,13 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger_dateonly]]")
 | 
			
		||||
 | 
			
		||||
    auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
 | 
			
		||||
    for (int i = 0; i < 10; ++i)
 | 
			
		||||
    {
 | 
			
		||||
#if !defined(SPDLOG_FMT_PRINTF)
 | 
			
		||||
        logger->info("Test message {}", i);
 | 
			
		||||
#else
 | 
			
		||||
        logger->info("Test message %d", i);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
    logger->flush();
 | 
			
		||||
    auto filename = w.str();
 | 
			
		||||
    REQUIRE(count_lines(filename) == 10);
 | 
			
		||||
@@ -142,7 +175,13 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger_custom]]")
 | 
			
		||||
 | 
			
		||||
    auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
 | 
			
		||||
    for (int i = 0; i < 10; ++i)
 | 
			
		||||
    {
 | 
			
		||||
#if !defined(SPDLOG_FMT_PRINTF)
 | 
			
		||||
        logger->info("Test message {}", i);
 | 
			
		||||
#else
 | 
			
		||||
        logger->info("Test message %d", i);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    logger->flush();
 | 
			
		||||
    auto filename = w.str();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user