3#include "util/SourceLocation.hpp"
28struct BenchmarkLoggingInitializer;
30struct LogServiceInitTests;
31struct LogFileRotationTests;
49#ifndef COVERAGE_ENABLED
51 if (auto clio_pump__ = x; not clio_pump__) { \
79 std::shared_ptr<spdlog::logger> logger_;
81 friend class LogService;
82 friend struct ::BenchmarkLoggingInitializer;
88 std::shared_ptr<spdlog::logger> logger_;
90 SourceLocationType
const sourceLocation_;
91 std::ostringstream stream_;
97 Pump(std::shared_ptr<spdlog::logger> logger,
Severity sev, SourceLocationType
const& loc);
99 Pump(Pump&&) =
delete;
100 Pump(Pump
const&) =
delete;
102 operator=(Pump
const&) =
delete;
104 operator=(Pump&&) =
delete;
114 template <
typename T>
115 [[maybe_unused]] Pump&
119 stream_ << std::forward<T>(
data);
126 operator bool()
const
133 static constexpr std::array<std::string_view, 8> kChannels = {
153 Logger(std::string_view
const channel);
160 operator=(
Logger const&) =
default;
163 operator=(
Logger&&) =
default;
172 trace(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
181 debug(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
190 info(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
199 warn(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
208 error(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
217 fatal(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
220 Logger(std::shared_ptr<spdlog::logger> logger);
231 friend struct ::LogServiceInitTests;
232 friend class ::LoggerFixture;
233 friend struct ::LogFileRotationTests;
235 friend class ::util::impl::OnAssert;
248 std::vector<std::shared_ptr<spdlog::sinks::sink>>
const& sinks
256 [[nodiscard]]
static bool
265 [[nodiscard]]
static bool
280 replaceSinks(std::vector<std::shared_ptr<spdlog::sinks::sink>>
const& sinks);
292 static std::shared_ptr<spdlog::logger>
293 registerLogger(std::string_view channel, std::optional<Severity> severity = std::nullopt);
296 static bool isAsync_;
298 static std::vector<std::shared_ptr<spdlog::sinks::sink>>
300 static bool initialized_;
311 LogService() =
delete;
319 [[nodiscard]]
static std::expected<void, std::string>
334 [[nodiscard]]
static Logger::Pump
335 trace(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
343 [[nodiscard]]
static Logger::Pump
344 debug(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
352 [[nodiscard]]
static Logger::Pump
353 info(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
361 [[nodiscard]]
static Logger::Pump
362 warn(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
370 [[nodiscard]]
static Logger::Pump
371 error(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
379 [[nodiscard]]
static Logger::Pump
380 fatal(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
389 [[nodiscard]]
static std::
390 expected<std::vector<std::shared_ptr<spdlog::sinks::sink>>, std::string>
393 struct RotationParams {
398 struct FileLoggingParams {
400 std::optional<RotationParams> rotation;
403 friend struct ::BenchmarkLoggingInitializer;
406 static std::shared_ptr<spdlog::sinks::sink>
407 createFileSink(FileLoggingParams
const& params, std::string
const& format);
Base state management class for the logging service.
Definition Logger.hpp:229
static bool initialized()
Whether the LogService is initialized or not.
Definition Logger.cpp:268
static void replaceSinks(std::vector< std::shared_ptr< spdlog::sinks::sink > > const &sinks)
Replace the current sinks with a new set of sinks.
Definition Logger.cpp:444
static void init(bool isAsync, Severity defaultSeverity, std::vector< std::shared_ptr< spdlog::sinks::sink > > const &sinks)
Initialize the logging core with specified parameters.
Definition Logger.cpp:241
static void reset()
Reset the logging service to uninitialized state.
Definition Logger.cpp:280
static std::shared_ptr< spdlog::logger > registerLogger(std::string_view channel, std::optional< Severity > severity=std::nullopt)
Register a new logger for the specified channel.
Definition Logger.cpp:292
static bool hasSinks()
Whether the LogService has any sink. If there is no sink, logger will not log messages anywhere.
Definition Logger.cpp:274
static Logger::Pump error(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::ERR severity.
Definition Logger.cpp:432
static Logger::Pump debug(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::DBG severity.
Definition Logger.cpp:414
static Logger::Pump warn(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::WRN severity.
Definition Logger.cpp:426
static void shutdown()
Shutdown spdlog to guarantee output is not lost.
Definition Logger.cpp:398
static std::expected< void, std::string > init(config::ClioConfigDefinition const &config)
Global log core initialization from a config::ClioConfigDefinition.
Definition Logger.cpp:364
static Logger::Pump fatal(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::FTL severity.
Definition Logger.cpp:438
static Logger::Pump trace(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::TRC severity.
Definition Logger.cpp:408
static Logger::Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::NFO severity.
Definition Logger.cpp:420
Pump warn(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::WRN severity.
Definition Logger.cpp:507
Pump error(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::ERR severity.
Definition Logger.cpp:512
Pump fatal(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::FTL severity.
Definition Logger.cpp:517
Pump debug(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::DBG severity.
Definition Logger.cpp:497
Pump trace(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::TRC severity.
Definition Logger.cpp:492
Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::NFO severity.
Definition Logger.cpp:502
Logger(std::string_view const channel)
Construct a new Logger object that produces loglines for the specified channel.
Definition Logger.cpp:450
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
This namespace contains various utilities.
Definition AccountUtils.hpp:11
Severity
Custom severity levels for util::Logger.
Definition Logger.hpp:61