mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 06:40:42 -07:00
logger: more fixes to deferred logging (troubleshooter) (#394)
## Description of change Various fixes to deferred logger - * Rename to "auto troubleshooter" * Fix potential deadlock * Reword the error messages to fit in a narrower column ## Testing tested all the error cases
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
#include "deferlog.h"
|
||||
#include "util/logging.h"
|
||||
@@ -9,14 +10,21 @@ namespace deferredlogs {
|
||||
"audio initialization error was previously detected during boot!",
|
||||
" (W:SuperstepSound: Audio device is not available!!!)",
|
||||
" this crash is most likely related to audio init failure",
|
||||
" see if the default audio device changed, fix your audio configuration (e.g., sample rate)",
|
||||
" double check your spice audio options/patches, and try again"
|
||||
" * check if the default audio device has changed",
|
||||
" * fix your audio device settings (e.g., sample rate)",
|
||||
" * double check your spice audio options and patches"
|
||||
};
|
||||
|
||||
std::mutex deferred_errors_mutex;
|
||||
std::vector<std::vector<std::string>> deferred_errors;
|
||||
std::atomic<bool> too_late;
|
||||
|
||||
void defer_error_messages(std::initializer_list<std::string> messages) {
|
||||
// don't try to acquire lock if already dumping to logger
|
||||
if (too_late) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(deferred_errors_mutex);
|
||||
deferred_errors.emplace_back(messages);
|
||||
}
|
||||
@@ -24,24 +32,25 @@ namespace deferredlogs {
|
||||
void dump_to_logger() {
|
||||
static std::once_flag printed;
|
||||
std::call_once(printed, []() {
|
||||
std::lock_guard<std::mutex> lock(deferred_errors_mutex);
|
||||
if (!deferred_errors.empty()) {
|
||||
log_warning("deferred_error",
|
||||
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log_warning("deferred_error", "");
|
||||
too_late = true;
|
||||
if (deferred_errors.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
log_warning("troubleshooter", "/------------------------ spice2x auto-troubleshooter ------------------------\\");
|
||||
log_warning("troubleshooter", "");
|
||||
|
||||
for (auto messages : deferred_errors) {
|
||||
for (auto message : messages) {
|
||||
log_warning("deferred_error", "{}", message);
|
||||
log_warning("troubleshooter", " {}", message);
|
||||
}
|
||||
log_warning("deferred_error", "");
|
||||
log_warning("troubleshooter", "");
|
||||
}
|
||||
|
||||
if (!deferred_errors.empty()) {
|
||||
log_warning("deferred_error",
|
||||
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
log_warning("troubleshooter", " Still unsure? Check the FAQ:");
|
||||
log_warning("troubleshooter", " https://github.com/spice2x/spice2x.github.io/wiki/Known-issues");
|
||||
log_warning("troubleshooter", "");
|
||||
log_warning("troubleshooter", "\\------------------------ spice2x auto-troubleshooter -----------------------/");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user