6
6
#include " quill/LogMacros.h"
7
7
#include " quill/sinks/FileSink.h"
8
8
9
+ #include < chrono>
9
10
#include < cstdio>
10
11
#include < string>
11
12
#include < vector>
@@ -52,6 +53,19 @@ TEST_CASE("backtrace_flush_on_error")
52
53
}
53
54
LOG_ERROR (logger, " After error" );
54
55
56
+ // flush here and resume test
57
+ logger->flush_log ();
58
+
59
+ // Enable backtrace for 2 messages for error
60
+ logger->init_backtrace (4 , LogLevel::Error);
61
+
62
+ for (size_t i = 0 ; i < 512 ; ++i)
63
+ {
64
+ LOG_BACKTRACE (logger, " More backtrace log {}" , i);
65
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
66
+ }
67
+ LOG_ERROR (logger, " After another error" );
68
+
55
69
logger->flush_log ();
56
70
Frontend::remove_logger (logger);
57
71
@@ -61,7 +75,7 @@ TEST_CASE("backtrace_flush_on_error")
61
75
// Read file and check
62
76
std::vector<std::string> const file_contents = quill::testing::file_contents (filename);
63
77
64
- REQUIRE_EQ (file_contents.size (), 4 );
78
+ REQUIRE_EQ (file_contents.size (), 9 );
65
79
66
80
std::string expected_string_1 = " LOG_INFO " + logger_name + " Before backtrace log" ;
67
81
REQUIRE (quill::testing::file_contains (file_contents, expected_string_1));
@@ -75,5 +89,20 @@ TEST_CASE("backtrace_flush_on_error")
75
89
std::string expected_string_4 = " LOG_BACKTRACE " + logger_name + " Backtrace log 11" ;
76
90
REQUIRE (quill::testing::file_contains (file_contents, expected_string_4));
77
91
92
+ std::string expected_string_5 = " LOG_BACKTRACE " + logger_name + " More backtrace log 508" ;
93
+ REQUIRE (quill::testing::file_contains (file_contents, expected_string_5));
94
+
95
+ std::string expected_string_6 = " LOG_BACKTRACE " + logger_name + " More backtrace log 509" ;
96
+ REQUIRE (quill::testing::file_contains (file_contents, expected_string_6));
97
+
98
+ std::string expected_string_7 = " LOG_BACKTRACE " + logger_name + " More backtrace log 510" ;
99
+ REQUIRE (quill::testing::file_contains (file_contents, expected_string_7));
100
+
101
+ std::string expected_string_8 = " LOG_BACKTRACE " + logger_name + " More backtrace log 511" ;
102
+ REQUIRE (quill::testing::file_contains (file_contents, expected_string_8));
103
+
104
+ std::string expected_string_9 = " LOG_ERROR " + logger_name + " After another error" ;
105
+ REQUIRE (quill::testing::file_contains (file_contents, expected_string_9));
106
+
78
107
testing::remove_file (filename);
79
108
}
0 commit comments