3#if !defined (LITEFX_LOGGING_API)
4# if defined(LiteFX_Logging_EXPORTS) && (defined _WIN32 || defined WINCE)
5# define LITEFX_LOGGING_API __declspec(dllexport)
6# elif (defined(LiteFX_Logging_EXPORTS) || defined(__APPLE__)) && defined __GNUC__ && __GNUC__ >= 4
7# define LITEFX_LOGGING_API __attribute__ ((visibility ("default")))
8# elif !defined(LiteFX_Logging_EXPORTS) && (defined _WIN32 || defined WINCE)
9# define LITEFX_LOGGING_API __declspec(dllimport)
13#ifndef LITEFX_LOGGING_API
14# define LITEFX_LOGGING_API
17#include <litefx/core.h>
19#include <spdlog/spdlog.h>
20#include <spdlog/sinks/sink.h>
25 enum class LITEFX_LOGGING_API LogLevel {
26 Trace = SPDLOG_LEVEL_TRACE,
27 Debug = SPDLOG_LEVEL_DEBUG,
28 Info = SPDLOG_LEVEL_INFO,
29 Warning = SPDLOG_LEVEL_WARN,
30 Error = SPDLOG_LEVEL_ERROR,
31 Fatal = SPDLOG_LEVEL_CRITICAL,
32 Off = SPDLOG_LEVEL_OFF,
36 class LITEFX_LOGGING_API
ISink {
55 virtual spdlog::sink_ptr
get()
const = 0;
62 ConsoleSink(
const LogLevel& level = LogLevel::Info,
const String& pattern =
"%+");
69 virtual LogLevel getLevel() const override;
72 virtual
String getName() const override;
75 virtual
String getPattern() const override;
78 virtual spdlog::sink_ptr get() const override;
85 RollingFileSink(
const String& fileName,
const LogLevel& level = LogLevel::Info,
const String& pattern =
"%+",
const bool& truncate =
false,
const int& maxFiles = 0);
92 virtual LogLevel getLevel() const override;
95 virtual
String getName() const override;
98 virtual
String getPattern() const override;
100 virtual
String getFileName() const;
102 virtual
bool getTruncate() const;
104 virtual
int getMaxFiles() const;
107 virtual spdlog::sink_ptr get() const override;
110 class LITEFX_LOGGING_API
Log {
111 LITEFX_IMPLEMENTATION(
LogImpl);
123 virtual inline const
String& getName() const noexcept;
126 virtual
void log(const LogLevel& level,
StringView message);
129 template<typename ...TArgs>
130 inline
void log(const LogLevel& level,
StringView format, TArgs&&... args) {
131 this->log(level,
fmt::format(fmt::runtime(format), std::forward<TArgs>(args)...));
134 template<
typename ...TArgs>
137 this->log(LogLevel::Trace, format, std::forward<TArgs>(args)...);
141 template<
typename ...TArgs>
144 this->log(LogLevel::Debug, format, std::forward<TArgs>(args)...);
148 template<
typename ...TArgs>
150 this->log(LogLevel::Info, format, std::forward<TArgs>(args)...);
153 template<
typename ...TArgs>
155 this->log(LogLevel::Warning, format, std::forward<TArgs>(args)...);
158 template<
typename ...TArgs>
160 this->log(LogLevel::Error, format, std::forward<TArgs>(args)...);
163 template<
typename ...TArgs>
165 this->log(LogLevel::Fatal, format, std::forward<TArgs>(args)...);
170 LITEFX_IMPLEMENTATION(LoggerImpl);
184 static
void sinkTo(const
ISink* sink);
190#define LITEFX_TRACE(log, format, ...) LiteFX::Logging::Logger::get(log).trace(format, __VA_ARGS__)
191#define LITEFX_DEBUG(log, format, ...) LiteFX::Logging::Logger::get(log).debug(format, __VA_ARGS__)
193#define LITEFX_TRACE(log, format, ...)
194#define LITEFX_DEBUG(log, format, ...)
197#define LITEFX_INFO(log, format, ...) LiteFX::Logging::Logger::get(log).info(format, __VA_ARGS__)
198#define LITEFX_WARNING(log, format, ...) LiteFX::Logging::Logger::get(log).warning(format, __VA_ARGS__)
199#define LITEFX_ERROR(log, format, ...) LiteFX::Logging::Logger::get(log).error(format, __VA_ARGS__)
200#define LITEFX_FATAL_ERROR(log, format, ...) LiteFX::Logging::Logger::get(log).fatal(format, __VA_ARGS__)
Definition: console.cpp:10
Definition: logging.hpp:58
virtual ~ConsoleSink() noexcept
ConsoleSink(const ConsoleSink &)=delete
ConsoleSink(ConsoleSink &&)=delete
Definition: logging.hpp:36
virtual String getName() const =0
Gets the name of the sink.
virtual spdlog::sink_ptr get() const =0
virtual String getPattern() const =0
Gets the pattern used to format the messages for the sink.
virtual LogLevel getLevel() const =0
Gets the minimum log level for messages to get written to the log.
Definition: logging.hpp:110
void error(StringView format, TArgs &&... args)
Definition: logging.hpp:159
void fatal(StringView format, TArgs &&... args)
Definition: logging.hpp:164
void debug(StringView format, TArgs &&... args)
Definition: logging.hpp:142
void trace(StringView format, TArgs &&... args)
Definition: logging.hpp:135
void warning(StringView format, TArgs &&... args)
Definition: logging.hpp:154
void info(StringView format, TArgs &&... args)
Definition: logging.hpp:149
Definition: logging.hpp:169
virtual ~Logger() noexcept
Logger(const Logger &)=delete
Logger & operator=(const Logger &)=delete
Definition: logging.hpp:81
RollingFileSink(const RollingFileSink &)=delete
virtual ~RollingFileSink() noexcept
RollingFileSink(RollingFileSink &&)=delete
Definition: logger.cpp:10
Definition: rolling_file.cpp:11
Definition: logging.hpp:22
std::string String
Definition: string.hpp:19
std::string_view StringView
Definition: string.hpp:21
auto format(LiteFX::Platform t, FormatContext &ctx) const
Definition: app_formatters.hpp:8