Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::interfaces::log_entry Struct Referenceexport

Standard log entry structure. More...

#include <logger_interface.h>

Collaboration diagram for kcenon::common::interfaces::log_entry:
Collaboration graph

Public Member Functions

 log_entry (log_level lvl=log_level::info, const std::string &msg="")
 Default constructor.
 
 log_entry (log_level lvl=log_level::info, const std::string &msg="")
 

Static Public Member Functions

static log_entry create (log_level lvl, std::string_view msg, const source_location &loc=source_location::current())
 Factory method to create a log_entry with source_location.
 
static log_entry create (log_level lvl, std::string_view msg, const source_location &loc=source_location::current())
 

Public Attributes

log_level level
 
std::string message
 
std::string file
 
int line
 
std::string function
 
std::chrono::system_clock::time_point timestamp
 
source_location location
 C++20 source_location (Issue #177)
 

Detailed Description

Standard log entry structure.

Note
Issue #177: Extended with source_location support. The file, line, and function fields are now populated from source_location when using the create() factory method.

Definition at line 65 of file logger.cppm.

Constructor & Destructor Documentation

◆ log_entry() [1/2]

kcenon::common::interfaces::log_entry::log_entry ( log_level lvl = log_level::info,
const std::string & msg = "" )
inline

Default constructor.

Parameters
lvlLog level (default: info)
msgLog message (default: empty)

Definition at line 99 of file logger_interface.h.

101 : level(lvl)
102 , message(msg)
103 , line(0)
104 , timestamp(std::chrono::system_clock::now())
105 , location() {}
log_level level
source_location location
C++20 source_location (Issue #177)
std::chrono::system_clock::time_point timestamp
int line
std::string message

◆ log_entry() [2/2]

kcenon::common::interfaces::log_entry::log_entry ( log_level lvl = log_level::info,
const std::string & msg = "" )
inlineexport

Definition at line 74 of file logger.cppm.

75 : level(lvl), message(msg), line(0), timestamp(std::chrono::system_clock::now()), location() {}

Member Function Documentation

◆ create() [1/2]

static log_entry kcenon::common::interfaces::log_entry::create ( log_level lvl,
std::string_view msg,
const source_location & loc = source_location::current() )
inlinestatic

Factory method to create a log_entry with source_location.

This is the preferred way to create log entries as it automatically captures the source location at the call site and populates the file, line, and function fields for backward compatibility.

Parameters
lvlLog level
msgLog message (string_view for efficiency)
locSource location (automatically captured at call site)
Returns
Fully initialized log_entry
auto entry = log_entry::create(log_level::info, "Operation completed");
// entry.file, entry.line, entry.function are automatically populated
static log_entry create(log_level lvl, std::string_view msg, const source_location &loc=source_location::current())
Factory method to create a log_entry with source_location.

Definition at line 124 of file logger_interface.h.

127 {
128
129 log_entry entry;
130 entry.level = lvl;
131 entry.message = std::string(msg);
132 entry.file = loc.file_name();
133 entry.line = loc.line();
134 entry.function = loc.function_name();
135 entry.timestamp = std::chrono::system_clock::now();
136 entry.location = loc;
137 return entry;
138 }
log_entry(log_level lvl=log_level::info, const std::string &msg="")
Default constructor.

◆ create() [2/2]

static log_entry kcenon::common::interfaces::log_entry::create ( log_level lvl,
std::string_view msg,
const source_location & loc = source_location::current() )
inlinestaticexport

Definition at line 77 of file logger.cppm.

78 {
79 log_entry entry;
80 entry.level = lvl;
81 entry.message = std::string(msg);
82 entry.file = loc.file_name();
83 entry.line = loc.line();
84 entry.function = loc.function_name();
85 entry.timestamp = std::chrono::system_clock::now();
86 entry.location = loc;
87 return entry;
88 }

References file, function, level, line, location, message, and timestamp.

Member Data Documentation

◆ file

std::string kcenon::common::interfaces::log_entry::file
export

Definition at line 88 of file logger_interface.h.

Referenced by create(), and kcenon::common::logging::ConsoleLogger::log().

◆ function

std::string kcenon::common::interfaces::log_entry::function
export

Definition at line 90 of file logger_interface.h.

Referenced by create().

◆ level

log_level kcenon::common::interfaces::log_entry::level
export

Definition at line 86 of file logger_interface.h.

Referenced by create(), and kcenon::common::logging::ConsoleLogger::log().

◆ line

int kcenon::common::interfaces::log_entry::line
export

Definition at line 89 of file logger_interface.h.

Referenced by create(), and kcenon::common::logging::ConsoleLogger::log().

◆ location

source_location kcenon::common::interfaces::log_entry::location
export

C++20 source_location (Issue #177)

Definition at line 92 of file logger_interface.h.

Referenced by create().

◆ message

std::string kcenon::common::interfaces::log_entry::message
export

Definition at line 87 of file logger_interface.h.

Referenced by create(), and kcenon::common::logging::ConsoleLogger::log().

◆ timestamp

std::chrono::system_clock::time_point kcenon::common::interfaces::log_entry::timestamp
export

Definition at line 91 of file logger_interface.h.

Referenced by create().


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