Skip to content

Commit f3107bc

Browse files
committed
Split startup trace into dedicated file on Windows
1 parent a9e8f1d commit f3107bc

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/gui/main_gui.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace {
3131

3232
FILE* g_startup_log_file = nullptr;
3333
std::string g_startup_log_path;
34+
std::string g_startup_trace_path;
3435

3536
void writeStartupLog(const char* fmt, ...) {
3637
if (!g_startup_log_file) return;
@@ -89,6 +90,15 @@ void initStartupLog() {
8990
// Ensure early LOG_* calls during App/Modem construction have a valid sink.
9091
ultra::setLogFile(g_startup_log_file);
9192
writeStartupLog("ProjectUltra GUI startup log initialized");
93+
94+
// Keep startup trace on a separate file to avoid mixed FILE* writers.
95+
std::filesystem::path trace_path = std::filesystem::path(g_startup_log_path).parent_path() / "startup_trace.log";
96+
if (FILE* tf = std::fopen(trace_path.string().c_str(), "w")) {
97+
std::fclose(tf); // Truncate for fresh run
98+
g_startup_trace_path = trace_path.string();
99+
} else {
100+
g_startup_trace_path.clear();
101+
}
92102
}
93103
}
94104

@@ -156,8 +166,13 @@ LONG WINAPI startupUnhandledExceptionFilter(EXCEPTION_POINTERS* ex) {
156166
int main(int argc, char* argv[]) {
157167
initStartupLog();
158168
#ifdef _WIN32
159-
if (!g_startup_log_path.empty()) {
169+
if (!g_startup_trace_path.empty()) {
170+
_putenv_s("ULTRA_STARTUP_LOG", g_startup_trace_path.c_str());
171+
writeStartupLog("Startup trace path: %s", g_startup_trace_path.c_str());
172+
} else if (!g_startup_log_path.empty()) {
173+
// Fallback only if dedicated trace path couldn't be created.
160174
_putenv_s("ULTRA_STARTUP_LOG", g_startup_log_path.c_str());
175+
writeStartupLog("Startup trace path fallback: %s", g_startup_log_path.c_str());
161176
}
162177
SetUnhandledExceptionFilter(startupUnhandledExceptionFilter);
163178
#endif

0 commit comments

Comments
 (0)