pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
AppUtils::Logger Class Reference

Manages application logging based on command-line arguments. More...

#include <logger.hpp>

Collaboration diagram for AppUtils::Logger:
Collaboration graph

Public Member Functions

 Logger (const CmdLine::CmdLineArgs &in_args)
 Initialises the logger and installs the custom message handler. More...
 
 ~Logger ()
 Restores the original message handler and cleans up logging resources, such as closing the log file. More...
 
 Logger (const Logger &)=delete
 
Loggeroperator= (const Logger &)=delete
 
 Logger (Logger &&)=delete
 
Loggeroperator= (Logger &&)=delete
 

Static Private Member Functions

static void messageHandler (QtMsgType type, const QMessageLogContext &context, const QString &msg)
 The static Qt message handler that intercepts all log messages. More...
 

Private Attributes

const CmdLine::CmdLineArgsargs_
 A reference to the parsed command-line arguments. More...
 
QSet< QtMsgType > activeLevels_
 The set of Qt message types to be logged. More...
 
QHash< QtMsgType, QString > levelPrefixes_
 A map from message type to its string prefix (e.g., “[debug]”). More...
 
std::unique_ptr< QFile > logFile_
 A smart pointer to the log file. More...
 
std::unique_ptr< QTextStream > logStream_
 A smart pointer to the text stream for writing to the log file. More...
 
QtMessageHandler oldHandler_ = nullptr
 Stores the original Qt message handler to be restored on exit. More...
 

Static Private Attributes

static Loggerinstance_ = nullptr
 Singleton instance of the logger. More...
 

Detailed Description

Manages application logging based on command-line arguments.

Definition at line 36 of file logger.hpp.

Constructor & Destructor Documentation

◆ Logger()

AppUtils::Logger::Logger ( const CmdLine::CmdLineArgs in_args)
inlineexplicit

Initialises the logger and installs the custom message handler.

Parameters
in_argsThe parsed command-line arguments.

Definition at line 44 of file logger.hpp.

◆ ~Logger()

AppUtils::Logger::~Logger ( )
inline

Restores the original message handler and cleans up logging resources, such as closing the log file.

Definition at line 91 of file logger.hpp.

Member Function Documentation

◆ messageHandler()

static void AppUtils::Logger::messageHandler ( QtMsgType  type,
const QMessageLogContext &  context,
const QString &  msg 
)
inlinestaticprivate

The static Qt message handler that intercepts all log messages.

This function filters messages based on the current log level and routes them to the configured outputs (console, file, syslog).

Parameters
typeThe level of the message (e.g., QtDebugMsg).
contextThe context where the message was generated.
msgThe log message.

Definition at line 123 of file logger.hpp.

Member Data Documentation

◆ activeLevels_

QSet<QtMsgType> AppUtils::Logger::activeLevels_
private

The set of Qt message types to be logged.

Definition at line 156 of file logger.hpp.

◆ args_

const CmdLine::CmdLineArgs& AppUtils::Logger::args_
private

A reference to the parsed command-line arguments.

Definition at line 153 of file logger.hpp.

◆ instance_

Logger* AppUtils::Logger::instance_ = nullptr
inlinestaticprivate

Singleton instance of the logger.

Definition at line 150 of file logger.hpp.

◆ levelPrefixes_

QHash<QtMsgType, QString> AppUtils::Logger::levelPrefixes_
private

A map from message type to its string prefix (e.g., “[debug]”).

Definition at line 162 of file logger.hpp.

◆ logFile_

std::unique_ptr<QFile> AppUtils::Logger::logFile_
private

A smart pointer to the log file.

Definition at line 165 of file logger.hpp.

◆ logStream_

std::unique_ptr<QTextStream> AppUtils::Logger::logStream_
private

A smart pointer to the text stream for writing to the log file.

Definition at line 171 of file logger.hpp.

◆ oldHandler_

QtMessageHandler AppUtils::Logger::oldHandler_ = nullptr
private

Stores the original Qt message handler to be restored on exit.

Definition at line 177 of file logger.hpp.


The documentation for this class was generated from the following file: