LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
util::Logger Class Reference

Application-wide logging singleton. More...

#include <Logger.hpp>

Collaboration diagram for util::Logger:
Collaboration graph

Static Public Member Functions

static void Initialize (LogLevel level=LogLevel::Info, const std::string &logFile="")
 Initializes the logger with default configuration.
 
static LogLevel fromStrLevel (const std::string &levelStr)
 Convert string to log level.
 
static void SetInstance (std::shared_ptr< ILogger > logger)
 Sets a custom logger instance (for testing)
 
static std::shared_ptr< ILogger > GetInstance ()
 Gets the current logger instance.
 
template<typename... Args>
static void Trace (fmt::format_string< Args... > fmt, Args &&... args)
 
template<typename... Args>
static void Debug (fmt::format_string< Args... > fmt, Args &&... args)
 
template<typename... Args>
static void Info (fmt::format_string< Args... > fmt, Args &&... args)
 
template<typename... Args>
static void Warn (fmt::format_string< Args... > fmt, Args &&... args)
 
template<typename... Args>
static void Error (fmt::format_string< Args... > fmt, Args &&... args)
 
template<typename... Args>
static void Critical (fmt::format_string< Args... > fmt, Args &&... args)
 
static void SetLevel (LogLevel level)
 Sets the global logging level.
 
static LogLevel GetLevel ()
 Gets the current logging level.
 

Static Private Attributes

static std::shared_ptr< ILogger > s_instance = nullptr
 

Detailed Description

Application-wide logging singleton.

Provides convenient static methods for logging throughout the application. Can be configured with a custom ILogger implementation for testing.

Example Usage:
Logger::Info("Application started");
Logger::Debug("Processing file: {}", filename);
Logger::Error("Failed to load config: {}", error);
static void Debug(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logger.hpp:285
static void Error(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logger.hpp:303
static void Info(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logger.hpp:291
Definition Error.hpp:17
Testing:
// In tests, inject a mock logger
auto mockLogger = std::make_shared<MockLogger>();
Logger::SetInstance(mockLogger);
static void SetInstance(std::shared_ptr< ILogger > logger)
Sets a custom logger instance (for testing)
Definition Logger.hpp:259

Member Function Documentation

◆ Critical()

template<typename... Args>
static void util::Logger::Critical ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Debug()

template<typename... Args>
static void util::Logger::Debug ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inlinestatic
Here is the call graph for this function:

◆ Error()

template<typename... Args>
static void util::Logger::Error ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inlinestatic
Here is the call graph for this function:

◆ fromStrLevel()

static LogLevel util::Logger::fromStrLevel ( const std::string &  levelStr)
inlinestatic

Convert string to log level.

Here is the caller graph for this function:

◆ GetInstance()

static std::shared_ptr< ILogger > util::Logger::GetInstance ( )
inlinestatic

Gets the current logger instance.

Returns
Shared pointer to logger
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLevel()

static LogLevel util::Logger::GetLevel ( )
inlinestatic

Gets the current logging level.

Returns
Current logging level
Here is the call graph for this function:

◆ Info()

template<typename... Args>
static void util::Logger::Info ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inlinestatic
Here is the call graph for this function:

◆ Initialize()

static void util::Logger::Initialize ( LogLevel  level = LogLevel::Info,
const std::string &  logFile = "" 
)
inlinestatic

Initializes the logger with default configuration.

Parameters
levelInitial logging level
logFileOptional file path for file logging
Here is the caller graph for this function:

◆ SetInstance()

static void util::Logger::SetInstance ( std::shared_ptr< ILogger >  logger)
inlinestatic

Sets a custom logger instance (for testing)

Parameters
loggerCustom logger implementation

◆ SetLevel()

static void util::Logger::SetLevel ( LogLevel  level)
inlinestatic

Sets the global logging level.

Parameters
levelNew logging level
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Trace()

template<typename... Args>
static void util::Logger::Trace ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Warn()

template<typename... Args>
static void util::Logger::Warn ( fmt::format_string< Args... >  fmt,
Args &&...  args 
)
inlinestatic
Here is the call graph for this function:

Member Data Documentation

◆ s_instance

std::shared_ptr< ILogger > util::Logger::s_instance = nullptr
inlinestaticprivate

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