Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
anonymous_namespace{logger.cpp} Namespace Reference

Classes

class  SourceLocationFormatterFlag
 

Functions

auto GenerateTimestamp () noexcept -> std::expected< std::string, std::string_view >
 
std::string FormatLogFileName (std::string_view logger_name, std::string_view pattern)
 

Variables

constexpr size_t kFormatBufferReserveSize = 256
 
constexpr size_t kMaxStackTraceFrames = 10
 
constexpr size_t kStackTraceReserveSize = 512
 

Function Documentation

◆ FormatLogFileName()

std::string anonymous_namespace{logger.cpp}::FormatLogFileName ( std::string_view  logger_name,
std::string_view  pattern 
)

Definition at line 283 of file logger.cpp.

283 {
284 std::string result(pattern);
285
286 size_t pos = result.find("{name}");
287 if (pos != std::string::npos) {
288 result.replace(pos, 6, logger_name);
289 }
290
291 pos = result.find("{timestamp}");
292 if (pos != std::string::npos) {
293 const std::string timestamp = GenerateTimestamp().value_or("unknown_time");
294 result.replace(pos, 11, timestamp);
295 }
296
297 return result;
298}
auto GenerateTimestamp() noexcept -> std::expected< std::string, std::string_view >
Definition logger.cpp:44

◆ GenerateTimestamp()

auto anonymous_namespace{logger.cpp}::GenerateTimestamp ( ) -> std::expected<std::string, std::string_view>
noexcept

Definition at line 44 of file logger.cpp.

44 {
45 try {
46 const auto now = std::chrono::system_clock::now();
47 const auto time_t_now = std::chrono::system_clock::to_time_t(now);
48
49 std::tm local_time{};
50
51 // Needed because of compatibility issues on Windows
52 // For more info: https://en.cppreference.com/w/c/chrono/localtime.html
53#ifdef HELIOS_PLATFORM_WINDOWS
54 const errno_t err = localtime_s(&local_time, &time_t_now);
55 if (err != 0) [[unlikely]] {
56 return std::unexpected("Failed to get local time");
57 }
58#else
59 const std::tm* const local_time_ptr = localtime_r(&time_t_now, &local_time);
60 if (local_time_ptr == nullptr) [[unlikely]] {
61 return std::unexpected("Failed to get local time");
62 }
63#endif
64
65 const int year = local_time.tm_year + 1900;
66 const int month = local_time.tm_mon + 1;
67 const int day = local_time.tm_mday;
68 const int hour = local_time.tm_hour;
69 const int min = local_time.tm_min;
70 const int sec = local_time.tm_sec;
71 return std::format("{:04d}-{:02d}-{:02d}_{:02d}-{:02d}-{:02d}", year, month, day, hour, min, sec);
72 } catch (...) {
73 return std::unexpected("Exception during timestamp generation");
74 }
75}

Variable Documentation

◆ kFormatBufferReserveSize

constexpr size_t anonymous_namespace{logger.cpp}::kFormatBufferReserveSize = 256
constexpr

Definition at line 40 of file logger.cpp.

◆ kMaxStackTraceFrames

constexpr size_t anonymous_namespace{logger.cpp}::kMaxStackTraceFrames = 10
constexpr

Definition at line 41 of file logger.cpp.

◆ kStackTraceReserveSize

constexpr size_t anonymous_namespace{logger.cpp}::kStackTraceReserveSize = 512
constexpr

Definition at line 42 of file logger.cpp.