From b3737c04c2db38b9d65bbb6365522657a996f55f Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 26 Dec 2023 22:03:49 +0100 Subject: [PATCH] Improve logging when opening a MIDI file * Flush debugging logs immediately after each message * Print "Opening song" before the related log messages --- src/MidiTrack.cpp | 1 + src/Song.cpp | 2 +- src/Util.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MidiTrack.cpp b/src/MidiTrack.cpp index 04cf299..e2005a1 100644 --- a/src/MidiTrack.cpp +++ b/src/MidiTrack.cpp @@ -93,6 +93,7 @@ void CMidiTrack::ppDebugTrack(int level, const char *msg, ...) vfprintf(stdout, msg, ap); va_end(ap); fputc('\n', stdout); + fflush(stdout); } dword_t CMidiTrack::readVarLen() diff --git a/src/Song.cpp b/src/Song.cpp index afa7c38..7389ef1 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -59,9 +59,9 @@ void CSong::loadSong(const QString & filename) #endif auto logLevelOk = false; auto logLevel = qEnvironmentVariableIntValue(PROJECT_VARNAME_UPPER "_MIDI_FILE_LOG_LEVEL", &logLevelOk); + ppLogInfo("Opening song %s", fn.toLocal8Bit().data()); m_midiFile->setLogLevel(logLevelOk ? logLevel : 3); m_midiFile->openMidiFile(std::string(fn.toLocal8Bit().data())); - ppLogInfo("Opening song %s", fn.toLocal8Bit().data()); transpose(0); midiFileInfo(); m_midiFile->setLogLevel(99); diff --git a/src/Util.cpp b/src/Util.cpp index 3cb6a67..aad7eb5 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -71,7 +71,7 @@ static void openLogFile() { static void flushLogs() { - if (logInfoFile != stdout && logsOpened) + if (logInfoFile && logsOpened) { fflush(logInfoFile); // logErrorFile is the same as logInfoFile