XPlor/libs/core/logmanager.h
njohnson 19459d7aaf Enhance LogManager with file output and entry buffering
- Add log-to-file functionality with configurable path
- Buffer log entries before listeners connect to prevent lost messages
- Add flush mechanism for buffered entries
- Improve utils.h with additional helper functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 12:11:16 -05:00

57 lines
1.4 KiB
C++

#ifndef LOGMANAGER_H
#define LOGMANAGER_H
#include <QObject>
#include <QString>
#include <QStringList>
#include <QFile>
#include <functional>
class LogManager : public QObject
{
Q_OBJECT
public:
static LogManager &instance() {
static LogManager instance;
return instance;
}
// Standard logging
void addEntry(const QString &entry);
void addError(const QString &error);
void addLine();
// Debug logging - only logs if debug mode enabled
void debug(const QString &entry);
// Set debug mode checker (called from Settings initialization)
void setDebugChecker(std::function<bool()> checker);
// Set log-to-file checker (called from Settings initialization)
void setLogToFileChecker(std::function<bool()> checker);
// Call this after connecting to entryAdded signal to replay buffered entries
void flushBufferedEntries();
signals:
void entryAdded(const QString &entry);
private:
LogManager() : m_debugChecker(nullptr), m_logToFileChecker(nullptr), m_logFile(nullptr), m_hasListeners(false) {}
~LogManager();
void writeToFile(const QString &entry);
void emitOrBuffer(const QString &entry);
std::function<bool()> m_debugChecker;
std::function<bool()> m_logToFileChecker;
QFile *m_logFile;
QStringList m_bufferedEntries;
bool m_hasListeners;
Q_DISABLE_COPY(LogManager)
};
#endif // LOGMANAGER_H