9#include <source_location>
42struct BenchmarkLoggingInitializer;
50struct LogServiceInitTests;
54struct LogFileRotationTests;
66#ifndef COVERAGE_ENABLED
76 if (auto clio_pump__ = x; not clio_pump__) \
111 std::shared_ptr<spdlog::logger> logger_;
113 friend class LogService;
114 friend struct ::BenchmarkLoggingInitializer;
120 std::shared_ptr<spdlog::logger> logger_;
122 std::source_location
const sourceLocation_;
123 std::ostringstream stream_;
129 Pump(std::shared_ptr<spdlog::logger> logger,
Severity sev, std::source_location
const& loc);
131 Pump(Pump&&) =
delete;
132 Pump(Pump
const&) =
delete;
134 operator=(Pump
const&) =
delete;
136 operator=(Pump&&) =
delete;
146 template <
typename T>
147 [[maybe_unused]] Pump&
151 stream_ << std::forward<T>(
data);
158 operator bool()
const
168 static constexpr std::array<std::string_view, 8>
kChannels = {
188 Logger(std::string_view
const channel);
200 operator=(
Logger const&) =
default;
203 operator=(
Logger&&) =
default;
212 trace(std::source_location
const& loc = std::source_location::current())
const;
221 debug(std::source_location
const& loc = std::source_location::current())
const;
230 info(std::source_location
const& loc = std::source_location::current())
const;
239 warn(std::source_location
const& loc = std::source_location::current())
const;
248 error(std::source_location
const& loc = std::source_location::current())
const;
257 fatal(std::source_location
const& loc = std::source_location::current())
const;
260 Logger(std::shared_ptr<spdlog::logger> logger);
271 friend struct ::LogServiceInitTests;
272 friend class ::LoggerFixture;
273 friend struct ::LogFileRotationTests;
275 friend class ::util::impl::OnAssert;
288 std::vector<std::shared_ptr<spdlog::sinks::sink>>
const& sinks
296 [[nodiscard]]
static bool
305 [[nodiscard]]
static bool
320 replaceSinks(std::vector<std::shared_ptr<spdlog::sinks::sink>>
const& sinks);
332 static std::shared_ptr<spdlog::logger>
333 registerLogger(std::string_view channel, std::optional<Severity> severity = std::nullopt);
336 static bool isAsync_;
338 static std::vector<std::shared_ptr<spdlog::sinks::sink>>
340 static bool initialized_;
351 LogService() =
delete;
359 [[nodiscard]]
static std::expected<void, std::string>
374 [[nodiscard]]
static Logger::Pump
375 trace(std::source_location
const& loc = std::source_location::current());
383 [[nodiscard]]
static Logger::Pump
384 debug(std::source_location
const& loc = std::source_location::current());
392 [[nodiscard]]
static Logger::Pump
393 info(std::source_location
const& loc = std::source_location::current());
401 [[nodiscard]]
static Logger::Pump
402 warn(std::source_location
const& loc = std::source_location::current());
410 [[nodiscard]]
static Logger::Pump
411 error(std::source_location
const& loc = std::source_location::current());
419 [[nodiscard]]
static Logger::Pump
420 fatal(std::source_location
const& loc = std::source_location::current());
429 [[nodiscard]]
static std::
430 expected<std::vector<std::shared_ptr<spdlog::sinks::sink>>, std::string>
433 struct RotationParams {
438 struct FileLoggingParams {
440 std::optional<RotationParams> rotation;
443 friend struct ::BenchmarkLoggingInitializer;
446 static std::shared_ptr<spdlog::sinks::sink>
447 createFileSink(FileLoggingParams
const& params, std::string
const& format);
Base state management class for the logging service.
Definition Logger.hpp:269
static bool initialized()
Whether the LogService is initialized or not.
Definition Logger.cpp:265
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:441
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:238
static void reset()
Reset the logging service to uninitialized state.
Definition Logger.cpp:277
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:289
static bool hasSinks()
Whether the LogService has any sink. If there is no sink, logger will not log messages anywhere.
Definition Logger.cpp:271
static Logger::Pump info(std::source_location const &loc=std::source_location::current())
Globally accessible General logger at Severity::NFO severity.
Definition Logger.cpp:417
static Logger::Pump error(std::source_location const &loc=std::source_location::current())
Globally accessible General logger at Severity::ERR severity.
Definition Logger.cpp:429
static Logger::Pump debug(std::source_location const &loc=std::source_location::current())
Globally accessible General logger at Severity::DBG severity.
Definition Logger.cpp:411
static void shutdown()
Shutdown spdlog to guarantee output is not lost.
Definition Logger.cpp:395
static Logger::Pump trace(std::source_location const &loc=std::source_location::current())
Globally accessible General logger at Severity::TRC severity.
Definition Logger.cpp:405
static std::expected< void, std::string > init(config::ClioConfigDefinition const &config)
Global log core initialization from a config::ClioConfigDefinition.
Definition Logger.cpp:361
static Logger::Pump fatal(std::source_location const &loc=std::source_location::current())
Globally accessible General logger at Severity::FTL severity.
Definition Logger.cpp:435
static Logger::Pump warn(std::source_location const &loc=std::source_location::current())
Globally accessible General logger at Severity::WRN severity.
Definition Logger.cpp:423
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
Pump info(std::source_location const &loc=std::source_location::current()) const
Interface for logging at Severity::NFO severity.
Definition Logger.cpp:499
~Logger()
Destroy the Logger; drops a dynamically created channel's logger from the spdlog registry once no oth...
Definition Logger.cpp:451
Pump error(std::source_location const &loc=std::source_location::current()) const
Interface for logging at Severity::ERR severity.
Definition Logger.cpp:509
Pump fatal(std::source_location const &loc=std::source_location::current()) const
Interface for logging at Severity::FTL severity.
Definition Logger.cpp:514
static constexpr std::array< std::string_view, 8 > kChannels
The predefined log channels; loggers for other channels are created dynamically.
Definition Logger.hpp:168
Pump debug(std::source_location const &loc=std::source_location::current()) const
Interface for logging at Severity::DBG severity.
Definition Logger.cpp:494
Pump trace(std::source_location const &loc=std::source_location::current()) const
Interface for logging at Severity::TRC severity.
Definition Logger.cpp:489
Pump warn(std::source_location const &loc=std::source_location::current()) const
Interface for logging at Severity::WRN severity.
Definition Logger.cpp:504
Logger(std::string_view const channel)
Construct a new Logger object that produces loglines for the specified channel.
Definition Logger.cpp:447
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
spdlog sinks (forward declarations only)
Definition Logger.hpp:30
The spdlog logging library (forward declarations only).
Definition Logger.hpp:20
Clio configuration: definitions of the supported keys, their types, constraints and defaults,...
Definition HandlerRegistry.hpp:24
This namespace contains various utilities.
Definition HandlerRegistry.hpp:24
Severity
Custom severity levels for util::Logger.
Definition Logger.hpp:93
@ WRN
Warning.
Definition Logger.hpp:97
@ TRC
Trace.
Definition Logger.hpp:94
@ NFO
Info.
Definition Logger.hpp:96
@ DBG
Debug.
Definition Logger.hpp:95
@ ERR
Error.
Definition Logger.hpp:98
@ FTL
Fatal.
Definition Logger.hpp:99