100 template <
typename... Args>
static void debug(
const std::string& message, Args&&... args)
108 template <
typename... Args>
static void info(
const std::string& message, Args&&... args)
110 log(
LogLevel::INFO, format(message, std::forward<Args>(args)...));
116 template <
typename... Args>
static void warn(
const std::string& message, Args&&... args)
118 log(
LogLevel::WARN, format(message, std::forward<Args>(args)...));
124 template <
typename... Args>
static void error(
const std::string& message, Args&&... args)
132 template <
typename... Args>
static void fatal(
const std::string& message, Args&&... args)
153 static void log(
LogLevel level,
const std::string& message);
154 static std::string getLevelString(
LogLevel level);
155 static std::string getCurrentTimestamp();
158 template <
typename T>
static std::string format(
const std::string& fmt, T&& arg)
160 size_t pos = fmt.find(
"{}");
161 if (pos == std::string::npos)
166 std::ostringstream oss;
169 std::string result = fmt;
170 result.replace(pos, 2, oss.str());
174 template <
typename T,
typename... Args>
175 static std::string format(
const std::string& fmt, T&& first, Args&&... rest)
177 std::string result = format(fmt, std::forward<T>(first));
178 return format(result, std::forward<Args>(rest)...);
181 static std::string format(
const std::string& fmt)
190 std::mutex logMutex_;
191 std::ofstream logFile_;
193 bool consoleOutput_ =
true;
194 bool timestamps_ =
true;
Thread-safe logging system with levels and optional file output.
static void setLogLevel(LogLevel level)
Set minimum log level.
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
static void error(const std::string &message, Args &&... args)
Log error message (recoverable failure).
static void setConsoleOutput(bool enabled)
Enable or disable console output.
static void shutdown()
Shutdown logger and close log file.
static void fatal(const std::string &message, Args &&... args)
Log fatal error message (application will terminate).
static void setTimestamps(bool enabled)
Enable or disable timestamps in log messages.
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
static void init(const std::string &logFilePath="", LogLevel minLevel=LogLevel::INFO)
Initialize logger with optional file output.
@ FATAL
Fatal errors (application will terminate).
@ WARN
Warning messages (non-critical issues).
@ INFO
General informational messages.
@ ERROR
Error messages (recoverable failures).
@ DEBUG
Verbose debugging information.