Skip to content

Commit a9e8f1d

Browse files
committed
Harden Win GUI startup logging and trace encoder ctor log
1 parent c50a130 commit a9e8f1d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

include/ultra/logging.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ inline void log(LogLevel level, const char* category, const char* format, ...) {
7575
FILE* out = g_log_file;
7676
if (!out) {
7777
#ifdef _WIN32
78-
// GUI-subsystem processes can have an invalid stderr stream on some Win10 setups.
79-
if (!stderr || _fileno(stderr) < 0) {
80-
return;
81-
}
82-
#endif
78+
// GUI-subsystem processes can have an invalid stderr stream on Win10.
79+
// Avoid using stderr entirely on Windows unless an explicit log file is set.
80+
return;
81+
#else
8382
out = stderr;
83+
#endif
8484
}
8585

8686
// Get elapsed time in milliseconds

src/gui/main_gui.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,17 @@ void initStartupLog() {
8686
}
8787

8888
if (g_startup_log_file) {
89+
// Ensure early LOG_* calls during App/Modem construction have a valid sink.
90+
ultra::setLogFile(g_startup_log_file);
8991
writeStartupLog("ProjectUltra GUI startup log initialized");
9092
}
9193
}
9294

9395
void closeStartupLog() {
9496
if (g_startup_log_file) {
97+
if (ultra::g_log_file == g_startup_log_file) {
98+
ultra::setLogFile(nullptr);
99+
}
95100
writeStartupLog("ProjectUltra GUI startup log closing");
96101
std::fclose(g_startup_log_file);
97102
g_startup_log_file = nullptr;

src/gui/modem/streaming_encoder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ StreamingEncoder::StreamingEncoder() {
5656
updateInterleaver();
5757
startupTrace("StreamingEncoder", "update-interleaver-exit");
5858

59+
startupTrace("StreamingEncoder", "ctor-log-enter");
5960
LOG_MODEM(INFO, "StreamingEncoder: Initialized (mode=%s, carriers=%d)",
6061
protocol::waveformModeToString(mode_), ofdm_config_.num_carriers);
62+
startupTrace("StreamingEncoder", "ctor-log-exit");
6163
startupTrace("StreamingEncoder", "ctor-exit");
6264
}
6365

0 commit comments

Comments
 (0)