Skip to content

Commit 7ee40d6

Browse files
committed
[GEN][ZH] Automatically add trailing new lines in debug log messages (#1232)
1 parent 808017e commit 7ee40d6

File tree

9 files changed

+61
-35
lines changed

9 files changed

+61
-35
lines changed

Core/Libraries/Source/WWVegas/WWStub/wwdebugstub.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void DebugLog(const char *format, ...)
3535
va_start(arg, format);
3636
vprintf(format, arg);
3737
va_end(arg);
38+
printf("\n");
3839
}
3940

4041
#endif
@@ -49,6 +50,7 @@ void DebugCrash(const char *format, ...)
4950
va_start(arg, format);
5051
vprintf(format, arg);
5152
va_end(arg);
53+
printf("\n");
5254

5355
// No exit in this stub
5456
}

Core/Tools/CRCDiff/debug.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ void DebugLog(const char *fmt, ...)
3737
buffer[1023] = 0;
3838
va_end( va );
3939

40-
printf( "%s", buffer );
40+
printf( "%s\n", buffer );
4141
OutputDebugString( buffer );
42+
OutputDebugString( "\n" );
4243
}
4344

4445
#endif // DEBUG

Core/Tools/Compress/Compress.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,24 @@
1717
*/
1818

1919
#include <string>
20-
#include <cstdio>
20+
#include <Utility/stdio_adapter.h>
21+
#include <cstdarg>
2122
#include "Lib/BaseTypeCore.h"
2223
#include "Compression.h"
2324

2425

2526
// TheSuperHackers @todo Streamline and simplify the logging approach for tools
26-
#define DEBUG_LOG(x) printf x
27+
static void DebugLog(const char* format, ...)
28+
{
29+
char buffer[1024];
30+
buffer[0] = 0;
31+
va_list args;
32+
va_start(args, format);
33+
vsnprintf(buffer, 1024, format, args);
34+
va_end(args);
35+
printf("%s\n", buffer);
36+
}
37+
#define DEBUG_LOG(x) DebugLog x
2738

2839

2940
void dumpHelp(const char *exe)

Core/Tools/PATCHGET/debug.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ static int doCrashBox(const char *buffer, bool logResult)
4444
case IDABORT:
4545
#ifdef DEBUG_LOGGING
4646
if (logResult)
47-
DebugLog("[Abort]\n");
47+
DebugLog("[Abort]");
4848
#endif
4949
_exit(1);
5050
break;
5151
case IDRETRY:
5252
#ifdef DEBUG_LOGGING
5353
if (logResult)
54-
DebugLog("[Retry]\n");
54+
DebugLog("[Retry]");
5555
#endif
5656
::DebugBreak();
5757
break;
5858
case IDIGNORE:
5959
#ifdef DEBUG_LOGGING
6060
// do nothing, just keep going
6161
if (logResult)
62-
DebugLog("[Ignore]\n");
62+
DebugLog("[Ignore]");
6363
#endif
6464
break;
6565
}
@@ -77,7 +77,8 @@ void DebugLog(const char *fmt, ...)
7777
va_end( va );
7878

7979
OutputDebugString(theBuffer);
80-
printf( "%s", theBuffer );
80+
OutputDebugString("\n");
81+
printf( "%s\n", theBuffer );
8182
}
8283

8384
#endif // defined(DEBUG) || defined(DEBUG_LOGGING)
@@ -98,9 +99,10 @@ void DebugCrash(const char *format, ...)
9899
::MessageBox(NULL, "String too long for debug buffers", "", MB_OK|MB_APPLMODAL);
99100

100101
OutputDebugString(theBuffer);
101-
printf( "%s", theBuffer );
102+
OutputDebugString("\n");
103+
printf( "%s\n", theBuffer );
102104

103-
strcat(theBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue\n");
105+
strcat(theBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue");
104106

105107
int result = doCrashBox(theBuffer, true);
106108

Core/Tools/matchbot/wlib/wdebug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ extern CritSec DebugLibSemaphore;
197197
__s << __FILE__ << "[" << __LINE__ << \
198198
"]: " << ##V << " = " << V << '\n' << '\0';\
199199
OutputDebugString(STRSTREAM_CSTR(__s));\
200+
OutputDebugString("\n");\
200201
DEBUGUNLOCK; \
201202
}
202203

@@ -211,6 +212,7 @@ extern CritSec DebugLibSemaphore;
211212
__s << "DBG [" << __FILE__ << \
212213
" " << __LINE__ << "] " << X << '\n' << '\0';\
213214
OutputDebugString(STRSTREAM_CSTR(__s));\
215+
OutputDebugString("\n");\
214216
DEBUGUNLOCK; \
215217
}
216218

@@ -223,6 +225,7 @@ extern CritSec DebugLibSemaphore;
223225
strstream __s;\
224226
__s << X << '\0';\
225227
OutputDebugString(STRSTREAM_CSTR(__s));\
228+
OutputDebugString("\n");\
226229
DEBUGUNLOCK; \
227230
}
228231

@@ -237,6 +240,7 @@ extern CritSec DebugLibSemaphore;
237240
__s << __FILE__ << "[" << __LINE__ << \
238241
"]: " << ##X << '\n' << '\0';\
239242
OutputDebugString(STRSTREAM_CSTR(__s));\
243+
OutputDebugString("\n");\
240244
DEBUGUNLOCK; \
241245
}
242246

Generals/Code/GameEngine/Source/Common/System/Debug.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void doLogOutput(const char *buffer)
233233
{
234234
if (theLogFile)
235235
{
236-
fprintf(theLogFile, "%s", buffer); // note, no \n (should be there already)
236+
fprintf(theLogFile, "%s\n", buffer);
237237
fflush(theLogFile);
238238
}
239239
}
@@ -242,10 +242,11 @@ static void doLogOutput(const char *buffer)
242242
if (theDebugFlags & DEBUG_FLAG_LOG_TO_CONSOLE)
243243
{
244244
::OutputDebugString(buffer);
245+
::OutputDebugString("\n");
245246
}
246247

247248
#ifdef INCLUDE_DEBUG_LOG_IN_CRC_LOG
248-
addCRCDebugLineNoCounter("%s", buffer);
249+
addCRCDebugLineNoCounter("%s\n", buffer);
249250
#endif
250251
}
251252
#endif
@@ -274,22 +275,22 @@ static int doCrashBox(const char *buffer, Bool logResult)
274275
case IDABORT:
275276
#ifdef DEBUG_LOGGING
276277
if (logResult)
277-
DebugLog("[Abort]\n");
278+
DebugLog("[Abort]");
278279
#endif
279280
_exit(1);
280281
break;
281282
case IDRETRY:
282283
#ifdef DEBUG_LOGGING
283284
if (logResult)
284-
DebugLog("[Retry]\n");
285+
DebugLog("[Retry]");
285286
#endif
286287
::DebugBreak();
287288
break;
288289
case IDIGNORE:
289290
#ifdef DEBUG_LOGGING
290291
// do nothing, just keep going
291292
if (logResult)
292-
DebugLog("[Ignore]\n");
293+
DebugLog("[Ignore]");
293294
#endif
294295
break;
295296
}
@@ -308,7 +309,7 @@ static void doStackDump()
308309
const int STACKTRACE_SKIP = 2;
309310
void* stacktrace[STACKTRACE_SIZE];
310311

311-
doLogOutput("\nStack Dump:\n");
312+
doLogOutput("\nStack Dump:");
312313
::FillStackAddresses(stacktrace, STACKTRACE_SIZE, STACKTRACE_SKIP);
313314
::StackDumpFromAddresses(stacktrace, STACKTRACE_SIZE, doLogOutput);
314315
}
@@ -396,7 +397,7 @@ void DebugInit(int flags)
396397
theLogFile = fopen(theLogFileName, "w");
397398
if (theLogFile != NULL)
398399
{
399-
DebugLog("Log %s opened: %s\n", theLogFileName, getCurrentTimeString());
400+
DebugLog("Log %s opened: %s", theLogFileName, getCurrentTimeString());
400401
}
401402
#endif
402403
}
@@ -494,7 +495,7 @@ void DebugCrash(const char *format, ...)
494495
#ifdef DEBUG_LOGGING
495496
if (ignoringAsserts())
496497
{
497-
doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!\n");
498+
doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!");
498499
}
499500
whackFunnyCharacters(theCrashBuffer);
500501
doLogOutput(theCrashBuffer);
@@ -506,7 +507,7 @@ void DebugCrash(const char *format, ...)
506507
}
507508
#endif
508509

509-
strcat(theCrashBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue\n");
510+
strcat(theCrashBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue");
510511

511512
int result = doCrashBox(theCrashBuffer, true);
512513

@@ -546,7 +547,7 @@ void DebugShutdown()
546547
#ifdef DEBUG_LOGGING
547548
if (theLogFile)
548549
{
549-
DebugLog("Log closed: %s\n", getCurrentTimeString());
550+
DebugLog("Log closed: %s", getCurrentTimeString());
550551
fclose(theLogFile);
551552
}
552553
theLogFile = NULL;
@@ -623,9 +624,9 @@ void SimpleProfiler::stopAndLog(const char *msg, int howOftenToLog, int howOften
623624
{
624625
m_numSessions = 0;
625626
m_totalAllSessions = 0;
626-
DEBUG_LOG(("%s: reset averages\n",msg));
627+
DEBUG_LOG(("%s: reset averages",msg));
627628
}
628-
DEBUG_ASSERTLOG(m_numSessions % howOftenToLog != 0, ("%s: %f msec, total %f msec, avg %f msec\n",msg,getTime(),getTotalTime(),getAverageTime()));
629+
DEBUG_ASSERTLOG(m_numSessions % howOftenToLog != 0, ("%s: %f msec, total %f msec, avg %f msec",msg,getTime(),getTotalTime(),getAverageTime()));
629630
}
630631

631632
// ----------------------------------------------------------------------------
@@ -682,7 +683,7 @@ double SimpleProfiler::getAverageTime()
682683
{
683684
if (theReleaseCrashLogFile)
684685
{
685-
fprintf(theReleaseCrashLogFile, "%s", buffer); // note, no \n (should be there already)
686+
fprintf(theReleaseCrashLogFile, "%s\n", buffer);
686687
fflush(theReleaseCrashLogFile);
687688
}
688689
}

Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static void WWDebug_Message_Callback(DebugType type, const char * message)
135135
{
136136
#ifdef RTS_DEBUG
137137
::OutputDebugString(message);
138+
::OutputDebugString("\n");
138139
#endif
139140
}
140141

@@ -143,6 +144,7 @@ static void WWAssert_Callback(const char * message)
143144
{
144145
#ifdef RTS_DEBUG
145146
::OutputDebugString(message);
147+
::OutputDebugString("\n");
146148
::DebugBreak();
147149
#endif
148150
}

GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static void doLogOutput(const char *buffer)
234234
{
235235
if (theLogFile)
236236
{
237-
fprintf(theLogFile, "%s", buffer); // note, no \n (should be there already)
237+
fprintf(theLogFile, "%s\n", buffer);
238238
fflush(theLogFile);
239239
}
240240
}
@@ -243,10 +243,11 @@ static void doLogOutput(const char *buffer)
243243
if (theDebugFlags & DEBUG_FLAG_LOG_TO_CONSOLE)
244244
{
245245
::OutputDebugString(buffer);
246+
::OutputDebugString("\n");
246247
}
247248

248249
#ifdef INCLUDE_DEBUG_LOG_IN_CRC_LOG
249-
addCRCDebugLineNoCounter("%s", buffer);
250+
addCRCDebugLineNoCounter("%s\n", buffer);
250251
#endif
251252
}
252253
#endif
@@ -275,22 +276,22 @@ static int doCrashBox(const char *buffer, Bool logResult)
275276
case IDABORT:
276277
#ifdef DEBUG_LOGGING
277278
if (logResult)
278-
DebugLog("[Abort]\n");
279+
DebugLog("[Abort]");
279280
#endif
280281
_exit(1);
281282
break;
282283
case IDRETRY:
283284
#ifdef DEBUG_LOGGING
284285
if (logResult)
285-
DebugLog("[Retry]\n");
286+
DebugLog("[Retry]");
286287
#endif
287288
::DebugBreak();
288289
break;
289290
case IDIGNORE:
290291
#ifdef DEBUG_LOGGING
291292
// do nothing, just keep going
292293
if (logResult)
293-
DebugLog("[Ignore]\n");
294+
DebugLog("[Ignore]");
294295
#endif
295296
break;
296297
}
@@ -309,7 +310,7 @@ static void doStackDump()
309310
const int STACKTRACE_SKIP = 2;
310311
void* stacktrace[STACKTRACE_SIZE];
311312

312-
doLogOutput("\nStack Dump:\n");
313+
doLogOutput("\nStack Dump:");
313314
::FillStackAddresses(stacktrace, STACKTRACE_SIZE, STACKTRACE_SKIP);
314315
::StackDumpFromAddresses(stacktrace, STACKTRACE_SIZE, doLogOutput);
315316
}
@@ -397,7 +398,7 @@ void DebugInit(int flags)
397398
theLogFile = fopen(theLogFileName, "w");
398399
if (theLogFile != NULL)
399400
{
400-
DebugLog("Log %s opened: %s\n", theLogFileName, getCurrentTimeString());
401+
DebugLog("Log %s opened: %s", theLogFileName, getCurrentTimeString());
401402
}
402403
#endif
403404
}
@@ -495,7 +496,7 @@ void DebugCrash(const char *format, ...)
495496
#ifdef DEBUG_LOGGING
496497
if (ignoringAsserts())
497498
{
498-
doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!\n");
499+
doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!");
499500
}
500501
whackFunnyCharacters(theCrashBuffer);
501502
doLogOutput(theCrashBuffer);
@@ -507,7 +508,7 @@ void DebugCrash(const char *format, ...)
507508
}
508509
#endif
509510

510-
strcat(theCrashBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue\n");
511+
strcat(theCrashBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue");
511512

512513
int result = doCrashBox(theCrashBuffer, true);
513514

@@ -547,7 +548,7 @@ void DebugShutdown()
547548
#ifdef DEBUG_LOGGING
548549
if (theLogFile)
549550
{
550-
DebugLog("Log closed: %s\n", getCurrentTimeString());
551+
DebugLog("Log closed: %s", getCurrentTimeString());
551552
fclose(theLogFile);
552553
}
553554
theLogFile = NULL;
@@ -624,9 +625,9 @@ void SimpleProfiler::stopAndLog(const char *msg, int howOftenToLog, int howOften
624625
{
625626
m_numSessions = 0;
626627
m_totalAllSessions = 0;
627-
DEBUG_LOG(("%s: reset averages\n",msg));
628+
DEBUG_LOG(("%s: reset averages",msg));
628629
}
629-
DEBUG_ASSERTLOG(m_numSessions % howOftenToLog != 0, ("%s: %f msec, total %f msec, avg %f msec\n",msg,getTime(),getTotalTime(),getAverageTime()));
630+
DEBUG_ASSERTLOG(m_numSessions % howOftenToLog != 0, ("%s: %f msec, total %f msec, avg %f msec",msg,getTime(),getTotalTime(),getAverageTime()));
630631
}
631632

632633
// ----------------------------------------------------------------------------
@@ -683,7 +684,7 @@ double SimpleProfiler::getAverageTime()
683684
{
684685
if (theReleaseCrashLogFile)
685686
{
686-
fprintf(theReleaseCrashLogFile, "%s", buffer); // note, no \n (should be there already)
687+
fprintf(theReleaseCrashLogFile, "%s\n", buffer);
687688
fflush(theReleaseCrashLogFile);
688689
}
689690
}

GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static void WWDebug_Message_Callback(DebugType type, const char * message)
135135
{
136136
#ifdef RTS_DEBUG
137137
::OutputDebugString(message);
138+
::OutputDebugString("\n");
138139
#endif
139140
}
140141

@@ -143,6 +144,7 @@ static void WWAssert_Callback(const char * message)
143144
{
144145
#ifdef RTS_DEBUG
145146
::OutputDebugString(message);
147+
::OutputDebugString("\n");
146148
::DebugBreak();
147149
#endif
148150
}

0 commit comments

Comments
 (0)