58#ifdef ENABLE_VECTOR_LOGGING
62#ifdef ENABLE_MAP_LOGGING
81#define LOG_LEVEL TRACE
83#define LOG_LEVEL DEBUG
89#define LOG_LEVEL ERROR
91#define LOG_LEVEL FATAL
184#ifdef ENABLE_VECTOR_LOGGING
194 for (
size_t i = 0; i < vec.size(); ++i) {
196 if (i != vec.size() - 1) {
205#ifdef ENABLE_MAP_LOGGING
214 template <
typename K,
typename V>
217 for (
auto it = m.begin(); it != m.end(); ++it) {
218 m_buffer << it->first <<
": " << it->second;
219 if (std::next(it) != m.end()) {
254 std::ostringstream m_buffer;
287 bool consoleOutput =
false);
308 explicit StreamLog(
const std::string &fileName,
bool consoleOutput =
false);
342 virtual std::stringstream
buildLog(
const std::string &message)
const;
362 bool createDirectories(
const std::string &path)
const;
RAII wrapper for building and committing log messages.
Definition streamlog.hpp:149
LogStatement(LogStatement &&other) noexcept
Move constructor.
LogStatement(StreamLog &logger)
Construct LogStatement bound to a logger.
LogStatement & operator<<(const char *value)
Stream insertion operator for C-strings.
Definition streamlog.hpp:179
LogStatement & operator<<(const T &value)
Stream insertion operator for generic types.
Definition streamlog.hpp:169
void appendToBuffer(const std::string &content)
Append content to buffer.
~LogStatement()
Destructor commits the log message.
void clearBuffer()
Clear the internal message buffer.
std::string getBufferContent() const
Get current buffer contents.
StreamLog & operator=(StreamLog &&)=delete
No move assignment.
virtual std::stringstream buildLog(const std::string &message) const
Build formatted log message with timestamp and level.
StreamLog(const StreamLog &)=delete
No copy constructor.
std::string levelToString(const LogLevel &level) const
Convert LogLevel enum to string.
StreamLog(StreamLog &&)=delete
No move constructor.
LogStatement getLogStatement(LogLevel level)
Create a LogStatement for the given log level.
StreamLog(const std::string &fileName, bool consoleOutput=false)
Construct logger with file and console settings.
StreamLog & operator=(const StreamLog &)=delete
No copy assignment.
LogLevel m_threshold
Minimum level to actually write (compile-time).
Definition streamlog.hpp:311
std::string getColor() const
Get ANSI color code for current log level.
void writeLog(const std::string &message)
Write formatted message to file and optionally console.
virtual ~StreamLog()
Virtual destructor for inheritance support.
std::string m_fileName
Path to log file.
Definition streamlog.hpp:313
bool m_consoleOutput
Whether to also write to stderr.
Definition streamlog.hpp:314
static StreamLog & instance(const std::string &fileName="output.log", bool consoleOutput=false)
Get the singleton logger instance.
LogStatement operator<<(std::ostream &(*manipulator)(std::ostream &))
Stream manipulator support (e.g., std::endl).
LogLevel m_level
Current log level being written.
Definition streamlog.hpp:310
virtual std::string getTimestamp() const
Get current timestamp.
void commitLog(const std::string &message)
Commit message if it meets threshold.
StreamLog::LogStatement log(LogLevel level)
Global logging function.
LogLevel
Log severity levels.
Definition streamlog.hpp:71
@ DEBUG
Debug information.
Definition streamlog.hpp:73
@ ERROR
Error conditions.
Definition streamlog.hpp:76
@ FATAL
Critical failures.
Definition streamlog.hpp:77
@ INFO
Informational messages.
Definition streamlog.hpp:74
@ WARN
Warning conditions.
Definition streamlog.hpp:75
@ TRACE
Detailed debugging information.
Definition streamlog.hpp:72
ANSI color codes for log levels.
Definition streamlog.hpp:100
static const std::string ErrorColor
ERROR level color.
Definition streamlog.hpp:105
static const std::string InfoColor
INFO level color.
Definition streamlog.hpp:103
static const std::string WarnColor
WARN level color.
Definition streamlog.hpp:104
static const std::string DebugColor
DEBUG level color.
Definition streamlog.hpp:102
static const std::string reset
Reset to default color.
Definition streamlog.hpp:107
static const std::string TraceColor
TRACE level color.
Definition streamlog.hpp:101
static const std::string FatalColor
FATAL level color.
Definition streamlog.hpp:106