80 auto now = std::chrono::system_clock::now();
81 auto time_t_now = std::chrono::system_clock::to_time_t(now);
82 std::tm* tm_now = std::localtime(&time_t_now);
84 std::ostringstream filename;
85 filename <<
"crash_" << std::put_time(tm_now,
"%Y%m%d_%H%M%S") <<
".log";
92 _open(
crash_log_path_.string().c_str(), _O_WRONLY | _O_CREAT | _O_TRUNC,
93 _S_IREAD | _S_IWRITE);
96 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
101 std::ostringstream header;
102 header <<
"=== YAZE Crash Report ===\n";
103 header <<
"Version: " <<
version_ <<
"\n";
104 header <<
"Timestamp: " << std::put_time(tm_now,
"%Y-%m-%d %H:%M:%S") <<
"\n";
105 header <<
"Platform: ";
108#elif defined(__APPLE__)
110#elif defined(__linux__)
116 header <<
"========================\n\n";
118 std::string header_str = header.str();
125 absl::FailureSignalHandlerOptions options;
126 options.symbolize_stacktrace =
true;
127 options.use_alternate_stack =
true;
128 options.call_previous_handler =
true;
135 absl::InstallFailureSignalHandler(options);
157 if (!std::filesystem::exists(crash_dir)) {
161 std::vector<std::filesystem::path> logs;
162 for (
const auto& entry : std::filesystem::directory_iterator(crash_dir)) {
163 if (entry.path().extension() ==
".log" &&
164 entry.path().filename().string().starts_with(
"crash_")) {
165 logs.push_back(entry.path());
174 std::sort(logs.begin(), logs.end(),
175 [](
const std::filesystem::path& a,
const std::filesystem::path& b) {
176 return std::filesystem::last_write_time(a) >
177 std::filesystem::last_write_time(b);
214 if (!std::filesystem::exists(crash_dir)) {
218 std::vector<std::filesystem::path> logs;
219 for (
const auto& entry : std::filesystem::directory_iterator(crash_dir)) {
220 if (entry.path().extension() ==
".log" &&
221 entry.path().filename().string().starts_with(
"crash_")) {
222 logs.push_back(entry.path());
226 if (
static_cast<int>(logs.size()) <= keep_count) {
231 std::sort(logs.begin(), logs.end(),
232 [](
const std::filesystem::path& a,
const std::filesystem::path& b) {
233 return std::filesystem::last_write_time(a) >
234 std::filesystem::last_write_time(b);
238 for (
size_t i = keep_count; i < logs.size(); ++i) {
240 std::filesystem::remove(logs[i], ec);