mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-04 20:05:51 +00:00
61 lines
2.2 KiB
C++
61 lines
2.2 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of clio: https://github.com/XRPLF/clio
|
|
Copyright (c) 2025, the clio developers.
|
|
|
|
Permission to use, copy, modify, and distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include "util/LoggerFixtures.hpp"
|
|
|
|
#include "util/log/Logger.hpp"
|
|
|
|
#include <spdlog/common.h>
|
|
#include <spdlog/pattern_formatter.h>
|
|
#include <spdlog/sinks/ostream_sink.h>
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <algorithm>
|
|
#include <memory>
|
|
|
|
LoggerFixture::LoggerFixture()
|
|
{
|
|
// Clear any existing loggers
|
|
spdlog::drop_all();
|
|
|
|
// Create ostream sink for testing
|
|
auto ostreamSink = std::make_shared<spdlog::sinks::ostream_sink_mt>(stream_);
|
|
ostreamSink->set_formatter(std::make_unique<spdlog::pattern_formatter>("%^%3!l:%n%$ - %v"));
|
|
|
|
// Create loggers for each channel
|
|
std::ranges::for_each(util::Logger::kCHANNELS, [&ostreamSink](char const* channel) {
|
|
auto logger = std::make_shared<spdlog::logger>(channel, ostreamSink);
|
|
logger->set_level(spdlog::level::trace);
|
|
spdlog::register_logger(logger);
|
|
});
|
|
|
|
spdlog::get("General")->set_level(spdlog::level::debug);
|
|
|
|
auto traceLogger = std::make_shared<spdlog::logger>("Trace", ostreamSink);
|
|
traceLogger->set_level(spdlog::level::trace);
|
|
spdlog::register_logger(traceLogger);
|
|
|
|
spdlog::set_default_logger(spdlog::get("General"));
|
|
}
|
|
|
|
NoLoggerFixture::NoLoggerFixture()
|
|
{
|
|
spdlog::set_level(spdlog::level::off);
|
|
}
|