Skip to content

Commit

Permalink
log: use localtime_r instead of std::localtime (#68)
Browse files Browse the repository at this point in the history
This is thread-safe and signal-safe.
  • Loading branch information
ammen99 authored Apr 16, 2024
1 parent 34f3bf9 commit 5cd0c8a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ static std::string get_formatted_date_time()
auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;

std::ostringstream out;
out << std::put_time(std::localtime(&tt), "%d-%m-%y %H:%M:%S.");

struct tm buffer;
localtime_r(&tt, &buffer);
out << std::put_time(&buffer, "%d-%m-%y %H:%M:%S.");
out << std::setfill('0') << std::setw(3) << ms.count();
return out.str();
}
Expand Down

0 comments on commit 5cd0c8a

Please sign in to comment.