Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions retinify/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,28 @@ struct LogMetadata

[[nodiscard]] auto GetCurrentTime() -> std::string
{
const std::chrono::system_clock::time_point currentTimePoint = std::chrono::system_clock::now();
const std::time_t currentTimeT = std::chrono::system_clock::to_time_t(currentTimePoint);
std::tm localTimeStruct{};
if (localtime_r(&currentTimeT, &localTimeStruct) == nullptr)
const std::time_t now = std::time(nullptr);

std::tm utc{};
#if defined(_WIN32)
if (gmtime_s(&utc, &now) != 0)
{
return {};
}
#else
if (gmtime_r(&now, &utc) == nullptr)
{
return std::string{"Invalid time"};
return {};
}
std::ostringstream timeStream;
timeStream << std::put_time(&localTimeStruct, "%F %T");
return timeStream.str();
#endif

char buffer[32];
if (std::strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", &utc) == 0)
{
return {};
}

return buffer;
}

inline auto Log(LogLevel level, const char *message, std::source_location location) noexcept -> void
Expand Down