Skip to content

Commit

Permalink
Log debug messages to stdout as well, and fixed release build LogDebu…
Browse files Browse the repository at this point in the history
…g macro.
  • Loading branch information
samizzo committed Apr 22, 2023
1 parent 257b797 commit a92a696
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ void Log(const char* prefix, const char* format, ...);
#if _DEBUG
#define LogDebug(...) Log("DEBUG: ", __VA_ARGS__)
#else
#define LogDebug(...) (void)
#define LogDebug(...)
#endif
2 changes: 2 additions & 0 deletions source/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
void Log(const char* prefix, const char* format, ...)
{
va_list args;
printf("%s", prefix);
OutputDebugString(prefix);
va_start(args, format);
int count = _vscprintf(format, args);
char* buffer = (char*)_alloca(count + 1);
vsprintf_s(buffer, count + 1, format, args);
OutputDebugString(buffer);
printf(buffer);
va_end(args);
}
3 changes: 3 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>
#include "Error.h"
#include "SaveRestoreConsole.h"
#include "Log.h"

using namespace std;

Expand All @@ -25,6 +26,8 @@ static void DisplayHelp()

int main(int argc, char** argv)
{
LogDebug("main\n");

#if defined(_DEBUG)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
Expand Down

0 comments on commit a92a696

Please sign in to comment.