Class Logger#
Defined in File logger.hpp
Inheritance Relationships#
Base Type#
public QObject
Class Documentation#
-
class Logger : public QObject#
Thread-safe application logger with file output and a Qt signal.
Logger is a singleton — access it via Logger::instance(). In practice, prefer the free functions (log_info, log_error, …) which automatically capture the call site via
std::source_location.- Connecting the UI panel
// In LoggerPanelW constructor (main thread): connect(&Logger::instance(), &Logger::entry_added, this, &LoggerPanelW::on_entry_added, Qt::QueuedConnection); // ← always use QueuedConnection
Note
The entry_added() signal is emitted from the calling thread. Always use Qt::QueuedConnection when connecting to a main-thread slot from a background worker.
Public Functions
-
~Logger() override#
-
void log(LogLevel level, const QString &message, std::source_location loc = std::source_location::current())#
Logs a message at the given severity level.
Thread-safe. If a log file is open, the message is written to it (mutex-protected). entry_added() is then emitted from the calling thread.
- Parameters:
level – Severity level.
message – UTF-8 message string.
loc – Automatically-captured source location — do not pass manually.
-
void set_min_level(LogLevel level)#
Sets the minimum level written to file and emitted via signal.
Messages below this level are discarded. Default: LogLevel::Trace.
- Parameters:
level – New minimum level.
-
bool open_log_file(const QString &path)#
Opens a log file for writing (appending if it already exists).
- Parameters:
path – Absolute file path.
- Returns:
trueon success.
-
void close_log_file()#
Flushes and closes the log file.
Signals
-
void entry_added(int level, QString timestamp, QString location, QString message)#
Emitted for every accepted log entry, from the calling thread.
- Parameters:
level – Severity as
int— cast back withstatic_cast<LogLevel>(level).timestamp – Wall-clock string, e.g.
"14:32:05.123".location – Source location, e.g.
"record_manager.cpp:88".message – The log message.