-
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathlog_capture.hpp
More file actions
39 lines (32 loc) · 1.02 KB
/
Copy pathlog_capture.hpp
File metadata and controls
39 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
This file is part of libhttpserver
Copyright (C) 2011-2026 Sebastiano Merlino
*/
// Shared test utility for capturing log_error output in integration tests.
// Extracted from hooks_handler_exception_fallback_to_hardcoded_500.cpp and
// hooks_handler_exception_user_handler_throws_continues_chain.cpp, where
// identical log_capture structs were duplicated verbatim.
//
// Usage:
// log_capture cap;
// auto logger = [&cap](const std::string& msg) { cap.append(msg); };
// webserver ws{create_webserver(PORT).log_error(logger)};
// // ... run test ...
// std::string buf = cap.read();
#ifndef TEST_INTEG_LOG_CAPTURE_HPP_
#define TEST_INTEG_LOG_CAPTURE_HPP_
#include <mutex>
#include <string>
struct log_capture {
std::mutex m;
std::string buf;
void append(const std::string& msg) {
std::lock_guard<std::mutex> g(m);
buf.append(msg).append("\n");
}
std::string read() {
std::lock_guard<std::mutex> g(m);
return buf;
}
};
#endif // TEST_INTEG_LOG_CAPTURE_HPP_