Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
Logger Class Reference

A singleton logging utility supporting multiple logging levels and concurrent logging to file and terminal. More...

#include <Logger.h>

Public Types

enum class  LogLevel {
  TRACE , VERBOSE , DEBUG , INFO ,
  WARN , ERROR
}
 Logging levels supported by the Logger. More...
 

Public Member Functions

void setLevel (LogLevel level)
 Sets the logging level.
 
void setLogDirectory (const std::string &directory, std::size_t maxSize=10048576)
 Sets the directory for storing log files.
 
void setEnabled (bool enabled)
 Enables or disables the Logger.
 
std::string getLogFilenameForThread (std::thread::id threadId)
 Retrieves the log filename for the specified thread.
 
std::string getLogFilenameWithSuffix (const std::string &baseName, int suffix)
 Retrieves a log filename with a suffix.
 
template<typename... Args>
void log (LogLevel messageLevel, const char *file, int line, const char *func, const char *errorType, const Args &... args) noexcept(false)
 Logs a message with the specified level and details.
 
 ~Logger ()
 Destructor for Logger, ensures graceful shutdown of logging.
 

Static Public Member Functions

static LoggergetInstance ()
 Retrieves the singleton instance of the Logger.
 

Public Attributes

std::thread::id threadId
 

Detailed Description

A singleton logging utility supporting multiple logging levels and concurrent logging to file and terminal.

Definition at line 53 of file Logger.h.

Member Enumeration Documentation

◆ LogLevel

enum class Logger::LogLevel
strong

Logging levels supported by the Logger.

Enumerator
TRACE 

Trace level for detailed memory information.

VERBOSE 

Verbose level for general debug messages.

DEBUG 

Debug level for debugging messages.

INFO 

Info level for informational messages.

WARN 

Warn level for warning messages.

ERROR 

Error level for critical error messages.

Definition at line 59 of file Logger.h.

Constructor & Destructor Documentation

◆ ~Logger()

Logger::~Logger ( )

Destructor for Logger, ensures graceful shutdown of logging.

Definition at line 25 of file Logger.cpp.

Member Function Documentation

◆ getInstance()

Logger * Logger::getInstance ( )
static

Retrieves the singleton instance of the Logger.

Returns
Pointer to the singleton Logger instance.

Definition at line 5 of file Logger.cpp.

◆ getLogFilenameForThread()

std::string Logger::getLogFilenameForThread ( std::thread::id  threadId)

Retrieves the log filename for the specified thread.

Parameters
threadIdThe thread ID.
Returns
Log filename associated with the specified thread.

Definition at line 80 of file Logger.cpp.

◆ getLogFilenameWithSuffix()

std::string Logger::getLogFilenameWithSuffix ( const std::string &  baseName,
int  suffix 
)

Retrieves a log filename with a suffix.

Parameters
baseNameBase name for the log file.
suffixInteger suffix for the filename.
Returns
Full filename with suffix.

Definition at line 74 of file Logger.cpp.

◆ log()

template<typename... Args>
void Logger::log ( LogLevel  messageLevel,
const char *  file,
int  line,
const char *  func,
const char *  errorType,
const Args &...  args 
)

Logs a message with the specified level and details.

Parameters
messageLevelThe logging level of the message.
fileSource file where the log is made.
lineLine number in the source file.
funcFunction name.
errorTypeOptional error type string for error-level logs.
argsThe message to log.
Exceptions
std::runtime_errorIf logging to file fails.

◆ setEnabled()

void Logger::setEnabled ( bool  enabled)

Enables or disables the Logger.

Parameters
enabledBoolean flag to enable or disable logging.

Definition at line 50 of file Logger.cpp.

◆ setLevel()

void Logger::setLevel ( LogLevel  level)

Sets the logging level.

Parameters
levelThe minimum logging level to be logged.

Definition at line 38 of file Logger.cpp.

◆ setLogDirectory()

void Logger::setLogDirectory ( const std::string &  directory,
std::size_t  maxSize = 10048576 
)

Sets the directory for storing log files.

Parameters
directoryDirectory path where log files are stored.
maxSizeMaximum allowed size for each log file in bytes, default is 10048576.

Definition at line 42 of file Logger.cpp.

Member Data Documentation

◆ threadId

std::thread::id Logger::threadId

The thread ID for logging purposes.

Definition at line 108 of file Logger.h.


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