3#include <litefx/config.h>
5#if !defined (LITEFX_LOGGING_API)
6# if defined(LiteFX_Logging_EXPORTS) && (defined _WIN32 || defined WINCE)
7# define LITEFX_LOGGING_API __declspec(dllexport)
8# elif (defined(LiteFX_Logging_EXPORTS) || defined(__APPLE__)) && defined __GNUC__ && __GNUC__ >= 4
9# define LITEFX_LOGGING_API __attribute__ ((visibility ("default")))
10# elif !defined(LiteFX_Logging_EXPORTS) && (defined _WIN32 || defined WINCE)
11# define LITEFX_LOGGING_API __declspec(dllimport)
15#ifndef LITEFX_LOGGING_API
16# define LITEFX_LOGGING_API
19#include <litefx/core.h>
20#include <spdlog/spdlog.h>
21#include <spdlog/sinks/sink.h>
30 Trace = SPDLOG_LEVEL_TRACE,
31 Debug = SPDLOG_LEVEL_DEBUG,
32 Info = SPDLOG_LEVEL_INFO,
34 Error = SPDLOG_LEVEL_ERROR,
35 Fatal = SPDLOG_LEVEL_CRITICAL,
36 Off = SPDLOG_LEVEL_OFF,
43 class LITEFX_LOGGING_API
ISink {
52 virtual ~
ISink() noexcept = default;
67 virtual
String getPattern() const = 0;
71 virtual spdlog::sink_ptr get() const = 0;
99 String getName() const override;
102 String getPattern() const override;
105 spdlog::sink_ptr get() const override;
136 String getName() const override;
139 String getPattern() const override;
145 virtual
String getFileName() const;
151 virtual
bool getTruncate() const;
157 virtual
int getMaxFiles() const;
160 spdlog::sink_ptr get() const override;
177 static constexpr std::uint32_t DEFAULT_TERMINATION_STATUS = 0xFF455252;
185 TerminationSink(
const LogLevel& level = LogLevel::Info,
int status =
static_cast<int>(DEFAULT_TERMINATION_STATUS));
198 String getName() const override;
201 String getPattern() const override;
204 spdlog::sink_ptr get() const override;
214 class LITEFX_LOGGING_API
Log {
215 LITEFX_IMPLEMENTATION(
LogImpl);
227 auto operator=(
Log&&) noexcept = delete;
228 auto operator=(const
Log&) = delete;
234 virtual const
String& getName() const noexcept;
245 template<typename ...TArgs>
246 inline
void log(
LogLevel level, std::format_string<TArgs...> format, TArgs&&... args) {
247 this->log(level, std::format(format, std::forward<TArgs>(args)...));
254 template<
typename ...TArgs>
255 inline void trace([[maybe_unused]] std::format_string<TArgs...> format, [[maybe_unused]] TArgs&&... args) {
257 this->log(LogLevel::Trace, format, std::forward<TArgs>(args)...);
265 template<
typename ...TArgs>
266 inline void debug([[maybe_unused]] std::format_string<TArgs...> format, [[maybe_unused]] TArgs&&... args) {
268 this->log(LogLevel::Debug, format, std::forward<TArgs>(args)...);
276 template<
typename ...TArgs>
277 inline void info(std::format_string<TArgs...> format, TArgs&&... args) {
278 this->log(LogLevel::Info, format, std::forward<TArgs>(args)...);
285 template<
typename ...TArgs>
286 inline void warning(std::format_string<TArgs...> format, TArgs&&... args) {
287 this->log(LogLevel::Warning, format, std::forward<TArgs>(args)...);
294 template<
typename ...TArgs>
295 inline void error(std::format_string<TArgs...> format, TArgs&&... args) {
296 this->log(LogLevel::Error, format, std::forward<TArgs>(args)...);
303 template<
typename ...TArgs>
304 inline void fatal(std::format_string<TArgs...> format, TArgs&&... args) {
305 this->log(LogLevel::Fatal, format, std::forward<TArgs>(args)...);
322 auto operator=(
Logger&&) noexcept = delete;
338 static
void sinkTo(const
ISink* sink);
346#define LITEFX_TRACE(log, format, ...) LiteFX::Logging::Logger::get(log).trace(format, ##__VA_ARGS__)
347#define LITEFX_DEBUG(log, format, ...) LiteFX::Logging::Logger::get(log).debug(format, ##__VA_ARGS__)
349#define LITEFX_TRACE(log, format, ...)
350#define LITEFX_DEBUG(log, format, ...)
353#define LITEFX_INFO(log, format, ...) LiteFX::Logging::Logger::get(log).info(format, ##__VA_ARGS__)
354#define LITEFX_WARNING(log, format, ...) LiteFX::Logging::Logger::get(log).warning(format, ##__VA_ARGS__)
355#define LITEFX_ERROR(log, format, ...) LiteFX::Logging::Logger::get(log).error(format, ##__VA_ARGS__)
356#define LITEFX_FATAL_ERROR(log, format, ...) LiteFX::Logging::Logger::get(log).fatal(format, ##__VA_ARGS__)
Definition console.cpp:10
Writes log messages to the console.
Definition logging.hpp:77
~ConsoleSink() noexcept override
Interface for a class that receives log messages.
Definition logging.hpp:43
A log to which messages are written to.
Definition logging.hpp:214
void debug(std::format_string< TArgs... > format, TArgs &&... args)
Logs a debug message with format .
Definition logging.hpp:266
void trace(std::format_string< TArgs... > format, TArgs &&... args)
Logs a trace message with format .
Definition logging.hpp:255
void error(std::format_string< TArgs... > format, TArgs &&... args)
Logs an error message with format .
Definition logging.hpp:295
void fatal(std::format_string< TArgs... > format, TArgs &&... args)
Logs a fatal error message with format .
Definition logging.hpp:304
void warning(std::format_string< TArgs... > format, TArgs &&... args)
Logs a warning message with format .
Definition logging.hpp:286
void info(std::format_string< TArgs... > format, TArgs &&... args)
Logs an info message with format .
Definition logging.hpp:277
A provider for Log instances.
Definition logging.hpp:312
virtual ~Logger() noexcept
Writes log messages to a rolling file.
Definition logging.hpp:111
~RollingFileSink() noexcept override
Forcefully terminates the application, if a log message of a certain level or higher is output.
Definition logging.hpp:170
~TerminationSink() noexcept override
Definition rolling_file.cpp:11
Definition termination.cpp:52
Definition logging.hpp:23
LogLevel
Defines the various log levels.
Definition logging.hpp:29
std::string String
Definition string.hpp:24
std::string_view StringView
Definition string.hpp:26