Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx::log_u::SSGXLogger Class Reference

Singleton class for managing logging within the SGX library. More...

#include <ssgx_log_u_logger.h>

Public Member Functions

void Init (const std::string &logger_name, const std::string &log_file, LogLevel log_level=ssgx::log_u::LogLevel::INFO, bool append_console=false)
 Initializes the logger with specified settings.
 
std::string GetLoggerName ()
 Retrieves the singleton instance of SSGXLogger.
 
void SetTraceId (const std::string &trace_id)
 Sets a trace ID for log messages.
 
bool IsInitialized ()
 
int WriteLog (ssgx::log_u::LogLevel log_level, const char *msg)
 Logs a message with the specified log level.
 
 SSGXLogger (const SSGXLogger &)=delete
 
SSGXLoggeroperator= (const SSGXLogger &)=delete
 

Static Public Member Functions

static SSGXLoggerGetInstance ()
 Retrieves the singleton instance of SSGXLogger.
 

Detailed Description

Singleton class for managing logging within the SGX library.

This class provides a centralized logging interface for the SGX library. It supports log level configuration, trace ID management, and the ability to initialize a logger with file and console appenders.

Usage:

auto& logger = SSGXLogger::GetInstance();
logger.Init("AppLogger", "app.log", SSGXLogger::INFO, true);
logger.SetTraceId("12345");
static SSGXLogger & GetInstance()
Retrieves the singleton instance of SSGXLogger.

Constructor & Destructor Documentation

◆ SSGXLogger()

ssgx::log_u::SSGXLogger::SSGXLogger ( const SSGXLogger & )
delete

Member Function Documentation

◆ GetInstance()

static SSGXLogger & ssgx::log_u::SSGXLogger::GetInstance ( )
static

Retrieves the singleton instance of SSGXLogger.

This method provides thread-safe access to the single instance of the logger.

Returns
Reference to the singleton instance of SSGXLogger.

◆ GetLoggerName()

std::string ssgx::log_u::SSGXLogger::GetLoggerName ( )
inline

Retrieves the singleton instance of SSGXLogger.

This method provides thread-safe access to the single instance of the logger.

Returns
Reference to the singleton instance of SSGXLogger.

◆ Init()

void ssgx::log_u::SSGXLogger::Init ( const std::string & logger_name,
const std::string & log_file,
LogLevel log_level = ssgx::log_u::LogLevel::INFO,
bool append_console = false )

Initializes the logger with specified settings.

Configures the logger with a given name, log file, log level, and optional console appender. This method should be called before logging any messages.

Parameters
logger_nameName of the logger (e.g., "AppLogger").
log_filePath to the log file.
log_levelLogging level to filter log messages.
append_consoleWhether to output log messages to the console. Default is false.

◆ IsInitialized()

bool ssgx::log_u::SSGXLogger::IsInitialized ( )

◆ operator=()

SSGXLogger & ssgx::log_u::SSGXLogger::operator= ( const SSGXLogger & )
delete

◆ SetTraceId()

void ssgx::log_u::SSGXLogger::SetTraceId ( const std::string & trace_id)

Sets a trace ID for log messages.

The trace ID is stored in the logging context and can be used to correlate log messages across different parts of the application. To include the trace ID in log messages, the log pattern must contain X{TraceId}.

Example:

void SetTraceId(const std::string &trace_id)
Sets a trace ID for log messages.
Parameters
trace_idThe trace ID string to be included in subsequent log messages.

◆ WriteLog()

int ssgx::log_u::SSGXLogger::WriteLog ( ssgx::log_u::LogLevel log_level,
const char * msg )

Logs a message with the specified log level.

This function logs a message to the configured log system with the specified log level. It ensures that the logger has been properly initialized before attempting to log the message.

Parameters
levelThe log level indicating the severity of the message. Possible values include INFO, WARNING, ERROR, DEBUG, FATAL, etc.
msgThe log message to be recorded.
Returns
0 - Success: The message was logged successfully.
-1 - Failure: The logger is not initialized or an error occurred during logging.

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