Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::utils::error_context Struct Reference

Structured error context for debugging. More...

#include <error_handling_utils.h>

Collaboration diagram for kcenon::logger::utils::error_context:
Collaboration graph

Public Member Functions

 error_context (logger_error_code error_code, std::string error_message, std::string op="", std::string file="", int line=0)
 Construct error context with manual location information.
 
std::string to_string () const
 Convert error context to a formatted string.
 

Public Attributes

logger_error_code code
 
std::string message
 
std::string operation
 
std::string source_file
 
int source_line
 
std::string function_name
 
std::chrono::system_clock::time_point timestamp
 

Detailed Description

Structured error context for debugging.

Provides additional context information for errors to aid in debugging and troubleshooting. This context can be used to track where and when errors occurred.

When C++20 source_location is available, location information is captured automatically. Otherwise, it can be provided manually.

Definition at line 42 of file error_handling_utils.h.

Constructor & Destructor Documentation

◆ error_context()

kcenon::logger::utils::error_context::error_context ( logger_error_code error_code,
std::string error_message,
std::string op = "",
std::string file = "",
int line = 0 )
inline

Construct error context with manual location information.

Parameters
error_codeThe logger error code
error_messageDetailed error message
opOperation being performed (optional)
fileSource file name (optional)
lineSource line number (optional)

Definition at line 80 of file error_handling_utils.h.

87 message(std::move(error_message)),
88 operation(std::move(op)),
89 source_file(std::move(file)),
90 source_line(line),
91 function_name(""),
92 timestamp(std::chrono::system_clock::now()) {}
logger_error_code error_code
std::chrono::system_clock::time_point timestamp

Member Function Documentation

◆ to_string()

std::string kcenon::logger::utils::error_context::to_string ( ) const
inline

Convert error context to a formatted string.

Returns
Formatted error message with context

Definition at line 99 of file error_handling_utils.h.

99 {
100 std::ostringstream oss;
101 oss << "[" << logger_error_to_string(code) << "]";
102 if (!message.empty()) {
103 oss << " " << message;
104 }
105 if (!operation.empty()) {
106 oss << " (during: " << operation << ")";
107 }
108 if (!source_file.empty()) {
109 oss << " at " << source_file;
110 if (source_line > 0) {
111 oss << ":" << source_line;
112 }
113 }
114 if (!function_name.empty()) {
115 oss << " in " << function_name << "()";
116 }
117 return oss.str();
118 }
std::string logger_error_to_string(logger_error_code code)
Convert logger_error_code to string representation.

References code, function_name, kcenon::logger::logger_error_to_string(), message, operation, source_file, and source_line.

Referenced by kcenon::logger::utils::log_error_context().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ code

logger_error_code kcenon::logger::utils::error_context::code

Definition at line 43 of file error_handling_utils.h.

Referenced by to_string().

◆ function_name

std::string kcenon::logger::utils::error_context::function_name

Definition at line 48 of file error_handling_utils.h.

Referenced by to_string().

◆ message

std::string kcenon::logger::utils::error_context::message

Definition at line 44 of file error_handling_utils.h.

Referenced by to_string().

◆ operation

std::string kcenon::logger::utils::error_context::operation

Definition at line 45 of file error_handling_utils.h.

Referenced by to_string().

◆ source_file

std::string kcenon::logger::utils::error_context::source_file

Definition at line 46 of file error_handling_utils.h.

Referenced by to_string().

◆ source_line

int kcenon::logger::utils::error_context::source_line

Definition at line 47 of file error_handling_utils.h.

Referenced by to_string().

◆ timestamp

std::chrono::system_clock::time_point kcenon::logger::utils::error_context::timestamp

Definition at line 49 of file error_handling_utils.h.


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