29 #pragma comment(lib, "Ws2_32.lib") 55 std::string hname =
"UNKNOWN";
56 char hchar[1024] =
"\0";
57 if (gethostname(hchar,
sizeof(hchar)) == 0) {
58 hname = std::string(hchar);
70 const auto pos = absolute_path.find_last_of(
"/\\");
71 return (absolute_path.substr(pos + 1));
84 std::vector<std::string> &stack_msg_vec)
87 void *addrlist[size + 1];
89 size_t no_of_stack_addresses =
90 backtrace(addrlist,
sizeof(addrlist) /
sizeof(
void *));
91 char **temp_symbols = backtrace_symbols(addrlist, no_of_stack_addresses);
94 std::vector<std::string> symbollist(temp_symbols,
95 temp_symbols + no_of_stack_addresses);
99 std::regex rgx(
"(^.*\\()(.*\\+)(0[xX][0-9a-fA-F]+\\))");
103 for (
const auto &symbol : symbollist) {
107 if (!std::regex_search(symbol, match, rgx)) {
108 stack_msg_vec.push_back(symbol);
112 std::string file = match[1].str();
113 file = file.substr(0, file.size() - 1);
114 std::string mangled_name = match[2].str();
115 mangled_name = mangled_name.substr(0, mangled_name.size() - 1);
116 std::string caller = match[3].str();
117 caller = caller.substr(0, caller.size() - 1);
123 abi::__cxa_demangle(mangled_name.c_str(), 0, 0, &status);
125 stack_msg_vec.emplace_back(file +
" : " + std::string(realname) +
128 stack_msg_vec.emplace_back(file +
" : " + mangled_name +
"()" +
"+" +
146 const std::string &time_format)
154 timeinfo = std::localtime(&t);
157 std::strftime(buffer, 80, time_format.c_str(), timeinfo);
158 return (std::string(buffer));
178 return utility::format_time_to_string(std::move(rawtime), time_format);
Main namespace for ealogger.
Definition: conversion_pattern.h:28
void stack_trace(unsigned int size, std::vector< std::string > &stack_msg_vec)
Print a demangled stacktrace.
Definition: utility.h:83
std::string format_time_to_string(std::time_t t, const std::string &time_format)
Get a formatted time string based on.
Definition: utility.h:145
std::string get_hostname()
Get local hostname.
Definition: utility.h:53
std::string get_file_name(const std::string &absolute_path)
Get the last element of a path.
Definition: utility.h:68
Namespace for ealogger utility functions.