6#include <userver/concurrent/variable.hpp>
7#include <userver/logging/impl/logger_base.hpp>
8#include <userver/utest/default_logger_fixture.hpp>
9#include <userver/utest/utest.hpp>
11USERVER_NAMESPACE_BEGIN
18class ToStringLogger :
public logging::impl::LoggerBase {
24 void Log(
logging::
Level level, std::string_view str)
override {
25 auto locked_ptr = log_.Lock();
26 *locked_ptr += fmt::format(
"level={}\t{}", logging::ToString(level), str);
29 std::string ExtractLog() {
30 auto locked_ptr = log_.Lock();
31 return std::exchange(*locked_ptr, std::string{});
35 concurrent::Variable<std::string, std::mutex> log_;
41template <
typename Base = ::testing::Test>
44 LogCaptureFixture() : logger_(std::make_shared<impl::ToStringLogger>()) {
45 utest::DefaultLoggerFixture<Base>::SetDefaultLogger(logger_);
52 std::shared_ptr<
impl::ToStringLogger> logger_;