48 QHash<CmdLine::LogLevel, QSet<QtMsgType>> logHierarchy;
49 logHierarchy[CmdLine::LogLevel::Debug] = {
50 QtDebugMsg, QtInfoMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg};
51 logHierarchy[CmdLine::LogLevel::Info] = {QtInfoMsg, QtWarningMsg,
52 QtCriticalMsg, QtFatalMsg};
53 logHierarchy[CmdLine::LogLevel::Warning] = {
54 QtWarningMsg, QtCriticalMsg, QtFatalMsg};
55 logHierarchy[CmdLine::LogLevel::Critical] = {QtCriticalMsg,
57 logHierarchy[CmdLine::LogLevel::Fatal] = {QtFatalMsg};
74 if (
logFile_->open(QIODevice::WriteOnly | QIODevice::Text)) {
78 <<
"Could not open log file:" <<
logFile_->fileName();
124 const QMessageLogContext& context,
125 const QString& msg) {
130 const QString prefix =
132 const QString formattedMsg = QString(
"%1 %2").arg(prefix, msg);
135 std::cout << formattedMsg.toStdString() <<
"\n";
140 syslog(LOG_INFO,
"%s", formattedMsg.toStdString().c_str());
Manages application logging based on command-line arguments.
std::unique_ptr< QTextStream > logStream_
A smart pointer to the text stream for writing to the log file.
std::unique_ptr< QFile > logFile_
A smart pointer to the log file.
QtMessageHandler oldHandler_
Stores the original Qt message handler to be restored on exit.
QHash< QtMsgType, QString > levelPrefixes_
A map from message type to its string prefix (e.g., “[debug]”).
static Logger * instance_
Singleton instance of the logger.
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
The static Qt message handler that intercepts all log messages.
QSet< QtMsgType > activeLevels_
The set of Qt message types to be logged.
const CmdLine::CmdLineArgs & args_
A reference to the parsed command-line arguments.
~Logger()
Restores the original message handler and cleans up logging resources, such as closing the log file.
Logger(const CmdLine::CmdLineArgs &in_args)
Initialises the logger and installs the custom message handler.
Command-line argument parsing and validation.
Namespace for application-wide utility functions, primarily for exception handling.
Holds and parses command-line arguments.
bool debug_console_
Flag to enable diagnostic output.
std::string debug_syslog_
Identifier for syslog logging.
LogLevel log_level_
Log level filter.
std::string debug_file_
File path for logging.