2
0

Log.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Utils/Log.h>
  6. #include <cstdarg>
  7. // Trace to TTY
  8. void TraceImpl(const char *inFMT, ...)
  9. {
  10. // Format the message
  11. va_list list;
  12. va_start(list, inFMT);
  13. char buffer[1024];
  14. vsnprintf(buffer, sizeof(buffer), inFMT, list);
  15. va_end(list);
  16. #ifdef JPH_PLATFORM_WINDOWS
  17. // Log to the output window
  18. strcat_s(buffer, "\n");
  19. OutputDebugStringA(buffer);
  20. #else
  21. // Log to the console
  22. printf("%s\n", buffer);
  23. #endif
  24. }
  25. void Alert(const char *inFMT, ...)
  26. {
  27. // Format the message
  28. va_list list;
  29. va_start(list, inFMT);
  30. char buffer[1024];
  31. vsnprintf(buffer, sizeof(buffer), inFMT, list);
  32. va_end(list);
  33. Trace("Alert: %s", buffer);
  34. #ifdef JPH_PLATFORM_WINDOWS
  35. MessageBoxA(nullptr, buffer, "Alert", MB_OK);
  36. #endif // JPH_PLATFORM_WINDOWS
  37. }
  38. void FatalError [[noreturn]] (const char *inFMT, ...)
  39. {
  40. // Format the message
  41. va_list list;
  42. va_start(list, inFMT);
  43. char buffer[1024];
  44. vsnprintf(buffer, sizeof(buffer), inFMT, list);
  45. va_end(list);
  46. Trace("Fatal Error: %s", buffer);
  47. #ifdef JPH_PLATFORM_WINDOWS
  48. MessageBoxA(nullptr, buffer, "Fatal Error", MB_OK);
  49. #endif // JPH_PLATFORM_WINDOWS
  50. exit(1);
  51. }