11#if __cplusplus >= 202002L
12#include <source_location>
34 : logger_(std::move(logger)), level_(level), caller_(std::move(caller)) {}
63 std::shared_ptr<ILogger> logger_;
66 std::ostringstream oss_;
69 class ILogger :
public std::enable_shared_from_this<ILogger> {
80 virtual void debug(
const std::string &message,
const std::string &caller =
"") = 0;
88 virtual void info(
const std::string &message,
const std::string &caller =
"") = 0;
96 virtual void warning(
const std::string &message,
const std::string &caller =
"") = 0;
104 virtual void error(
const std::string &message,
const std::string &caller =
"") = 0;
112 virtual void critical(
const std::string &message,
const std::string &caller =
"") = 0;
166 return LogStream{shared_from_this(), level, caller};
227 template <
typename... Args>
228 void debugFmt(
const std::string &format, Args &&...args);
237 template <
typename... Args>
238 void infoFmt(
const std::string &format, Args &&...args);
247 template <
typename... Args>
248 void warningFmt(
const std::string &format, Args &&...args);
257 template <
typename... Args>
258 void errorFmt(
const std::string &format, Args &&...args);
267 template <
typename... Args>
268 void criticalFmt(
const std::string &format, Args &&...args);
270#if __cplusplus >= 202002L
279 void debugWithLocation(
const std::string &message,
280 const std::source_location &location = std::source_location::current()) {
282 <<
"File: " << location.file_name() <<
"\n"
283 <<
"Function: " << location.function_name() <<
"\n"
284 <<
"Line: " << location.line() <<
"\n";
293 void infoWithLocation(
const std::string &message,
294 const std::source_location &location = std::source_location::current()) {
296 <<
"File: " << location.file_name() <<
"\n"
297 <<
"Function: " << location.function_name() <<
"\n"
298 <<
"Line: " << location.line() <<
"\n";
307 void warningWithLocation(
const std::string &message,
const std::source_location &location =
308 std::source_location::current()) {
310 <<
"File: " << location.file_name() <<
"\n"
311 <<
"Function: " << location.function_name() <<
"\n"
312 <<
"Line: " << location.line() <<
"\n";
321 void errorWithLocation(
const std::string &message,
322 const std::source_location &location = std::source_location::current()) {
324 <<
"File: " << location.file_name() <<
"\n"
325 <<
"Function: " << location.function_name() <<
"\n"
326 <<
"Line: " << location.line() <<
"\n";
335 void criticalWithLocation(
const std::string &message,
const std::source_location &location =
336 std::source_location::current()) {
338 <<
"File: " << location.file_name() <<
"\n"
339 <<
"Function: " << location.function_name() <<
"\n"
340 <<
"Line: " << location.line() <<
"\n";
350 const std::string message = oss_.str();
361 template <
typename... Args>
363 std::string message = fmt::vformat(format, fmt::make_format_args(args...));
367 template <
typename... Args>
369 std::string message = fmt::vformat(format, fmt::make_format_args(args...));
373 template <
typename... Args>
375 std::string message = fmt::vformat(format, fmt::make_format_args(args...));
379 template <
typename... Args>
381 std::string message = fmt::vformat(format, fmt::make_format_args(args...));
385 template <
typename... Args>
387 std::string message = fmt::vformat(format, fmt::make_format_args(args...));
virtual void info(const std::string &message, const std::string &caller="")=0
Log an info message.
virtual bool enableFileLogging(const std::string &filename)=0
Enable logging to a file.
LogStream errorStream(const std::string &caller="")
Create a LogStream for streaming error messages.
Definition ILogger.hpp:205
LogStream warningStream(const std::string &caller="")
Create a LogStream for streaming warning messages.
Definition ILogger.hpp:195
LogStream debugStream(const std::string &caller="")
Create a LogStream for streaming debug messages.
Definition ILogger.hpp:177
virtual void warning(const std::string &message, const std::string &caller="")=0
Log a warning message.
virtual void disableFileLogging()=0
Disable logging to a file.
virtual std::string getAppPrefix() const =0
Get the App Prefix object.
void infoFmt(const std::string &format, Args &&...args)
Create a formatted info message.
Definition ILogger.hpp:368
virtual void critical(const std::string &message, const std::string &caller="")=0
Log a critical message.
virtual void debug(const std::string &message, const std::string &caller="")=0
Log a debug message.
virtual void setLevel(Level level)=0
Set the Level object.
LogStream infoStream(const std::string &caller="")
Create a LogStream for streaming info messages.
Definition ILogger.hpp:187
void debugFmt(const std::string &format, Args &&...args)
Create a formatted debug message.
Definition ILogger.hpp:362
virtual Level getLevel() const =0
Get the Level object.
LogStream criticalStream(const std::string &caller="")
Create a LogStream for streaming critical messages.
Definition ILogger.hpp:215
virtual void error(const std::string &message, const std::string &caller="")=0
Log an error message.
void criticalFmt(const std::string &format, Args &&...args)
Create a formatted critical message.
Definition ILogger.hpp:386
LogStream stream(Level level, const std::string &caller="")
Create a LogStream for streaming log messages.
Definition ILogger.hpp:165
void errorFmt(const std::string &format, Args &&...args)
Create a formatted error message.
Definition ILogger.hpp:380
virtual void setAppPrefix(const std::string &prefix)=0
Set the application prefix for log messages.
void warningFmt(const std::string &format, Args &&...args)
Create a formatted warning message.
Definition ILogger.hpp:374
virtual ~ILogger()=default
Helper class for streaming log messages.
Definition ILogger.hpp:31
LogStream(std::shared_ptr< ILogger > logger, Level level, std::string caller)
Definition ILogger.hpp:33
~LogStream()
Destroy the Log Stream:: Log Stream object.
Definition ILogger.hpp:349
LogStream & operator<<(const T &value)
Stream a value into the log message.
Definition ILogger.hpp:46
LogStream & operator<<(std::ostream &(*manip)(std::ostream &))
Stream a manipulator into the log message (e.g., std::endl)
Definition ILogger.hpp:57
Definition ILogger.hpp:15
Level
Logging levels.
Definition ILogger.hpp:21
@ LOG_CRITICAL
Definition ILogger.hpp:21
@ LOG_INFO
Definition ILogger.hpp:21
@ LOG_ERROR
Definition ILogger.hpp:21
@ LOG_WARNING
Definition ILogger.hpp:21
@ LOG_DEBUG
Definition ILogger.hpp:21