22#include "util/SourceLocation.hpp"
47struct BenchmarkLoggingInitializer;
49struct LogServiceInitTests;
66#ifndef COVERAGE_ENABLED
68 if (auto clio_pump__ = x; not clio_pump__) { \
96 std::shared_ptr<spdlog::logger> logger_;
98 friend class LogService;
99 friend struct ::BenchmarkLoggingInitializer;
105 std::shared_ptr<spdlog::logger> logger_;
107 SourceLocationType
const sourceLocation_;
108 std::ostringstream stream_;
114 Pump(std::shared_ptr<spdlog::logger> logger,
Severity sev, SourceLocationType
const& loc);
116 Pump(Pump&&) =
delete;
117 Pump(Pump
const&) =
delete;
119 operator=(Pump
const&) =
delete;
121 operator=(Pump&&) =
delete;
130 template <
typename T>
131 [[maybe_unused]] Pump&
135 stream_ << std::forward<T>(
data);
142 operator bool()
const
149 static constexpr std::array<std::string_view, 8> kCHANNELS = {
169 Logger(std::string_view
const channel);
176 operator=(
Logger const&) =
default;
179 operator=(
Logger&&) =
default;
188 trace(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
197 debug(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
206 info(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
215 warn(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
224 error(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
233 fatal(SourceLocationType
const& loc = CURRENT_SRC_LOCATION)
const;
236 Logger(std::shared_ptr<spdlog::logger> logger);
247 friend struct ::LogServiceInitTests;
248 friend class ::LoggerFixture;
250 friend class ::util::impl::OnAssert;
260 init(
bool isAsync,
Severity defaultSeverity, std::vector<std::shared_ptr<spdlog::sinks::sink>>
const& sinks);
267 [[nodiscard]]
static bool
275 [[nodiscard]]
static bool
290 replaceSinks(std::vector<std::shared_ptr<spdlog::sinks::sink>>
const& sinks);
302 static std::shared_ptr<spdlog::logger>
303 registerLogger(std::string_view channel, std::optional<Severity> severity = std::nullopt);
306 static bool isAsync_;
308 static std::vector<std::shared_ptr<spdlog::sinks::sink>> sinks_;
309 static bool initialized_;
320 LogService() =
delete;
328 [[nodiscard]]
static std::expected<void, std::string>
343 [[nodiscard]]
static Logger::Pump
344 trace(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
352 [[nodiscard]]
static Logger::Pump
353 debug(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
361 [[nodiscard]]
static Logger::Pump
362 info(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
370 [[nodiscard]]
static Logger::Pump
371 warn(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
379 [[nodiscard]]
static Logger::Pump
380 error(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
388 [[nodiscard]]
static Logger::Pump
389 fatal(SourceLocationType
const& loc = CURRENT_SRC_LOCATION);
398 [[nodiscard]]
static std::expected<std::vector<std::shared_ptr<spdlog::sinks::sink>>, std::string>
401 struct FileLoggingParams {
404 uint32_t rotationSizeMB;
405 uint32_t dirMaxFiles;
408 friend struct ::BenchmarkLoggingInitializer;
411 static std::shared_ptr<spdlog::sinks::sink>
412 createFileSink(FileLoggingParams
const& params, std::string
const& format);
Base state management class for the logging service.
Definition Logger.hpp:245
static bool initialized()
Whether the LogService is initialized or not.
Definition Logger.cpp:269
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:432
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:246
static void reset()
Reset the logging service to uninitialized state.
Definition Logger.cpp:281
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:293
static bool hasSinks()
Whether the LogService has any sink. If there is no sink, logger will not log messages anywhere.
Definition Logger.cpp:275
static Logger::Pump error(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::ERR severity.
Definition Logger.cpp:420
static Logger::Pump debug(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::DBG severity.
Definition Logger.cpp:402
static Logger::Pump warn(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::WRN severity.
Definition Logger.cpp:414
static void shutdown()
Shutdown spdlog to guarantee output is not lost.
Definition Logger.cpp:387
static std::expected< void, std::string > init(config::ClioConfigDefinition const &config)
Global log core initialization from a config::ClioConfigDefinition.
Definition Logger.cpp:353
static Logger::Pump fatal(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::FTL severity.
Definition Logger.cpp:426
static Logger::Pump trace(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::TRC severity.
Definition Logger.cpp:396
static Logger::Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION)
Globally accessible General logger at Severity::NFO severity.
Definition Logger.cpp:408
Pump warn(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::WRN severity.
Definition Logger.cpp:491
Pump error(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::ERR severity.
Definition Logger.cpp:496
Pump fatal(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::FTL severity.
Definition Logger.cpp:501
Pump debug(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::DBG severity.
Definition Logger.cpp:481
Pump trace(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::TRC severity.
Definition Logger.cpp:476
Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::NFO severity.
Definition Logger.cpp:486
Logger(std::string_view const channel)
Construct a new Logger object that produces loglines for the specified channel.
Definition Logger.cpp:438
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:50
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70
This namespace contains various utilities.
Definition AccountUtils.hpp:30
Severity
Custom severity levels for util::Logger.
Definition Logger.hpp:78