Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #if !defined(LACE_LOG_H)
  2. #define LACE_LOG_H
  3.  
  4. enum log_severity
  5. {
  6. Display,
  7. Info,
  8. Warning,
  9. Error,
  10.  
  11. Count
  12. };
  13.  
  14. struct lace_log
  15. {
  16. // Empty;
  17. };
  18.  
  19.  
  20. #define LACE_LOG_CATEGORY(name) lace_log name;
  21.  
  22. #define LACE_LOG(Category, Severity, Format, ...) \
  23. LogInternal(__FILE__, __LINE__, #Category, Severity, Format, ##__VA_ARGS__)
  24.  
  25. #define COLOR_CODE_RED "\x1B[31m"
  26. #define COLOR_CODE_YELLOW "\x1B[33m"
  27. #define COLOR_CODE_WHITE "\x1B[37m"
  28. #define COLOR_CODE_NORMAL "\x1B[0m"
  29.  
  30. static void
  31. OutputDebugStringWithColor(char *String, lace_log_color Color)
  32. {
  33. char *ColorCode;
  34. if(Color == Red)
  35. {
  36. ColorCode = COLOR_CODE_RED;
  37. }
  38. else if(Color == Yellow)
  39. {
  40. ColorCode = COLOR_CODE_YELLOW;
  41. }
  42. else if(Color == White)
  43. {
  44. ColorCode = COLOR_CODE_WHITE;
  45. }
  46. else
  47. {
  48. ColorCode = COLOR_CODE_NORMAL;
  49. }
  50.  
  51. // TODO(zak): On Windows were usually logging to visual studio output and not
  52. // a normal console. Do a more verbose check here to see what were logging to in the future
  53. #if !PLATFORM_WINDOWS
  54. Prepend(String, ColorCode);
  55. #endif
  56.  
  57. Platform.OutputDebugString(String);
  58. }
  59.  
  60.  
  61. static void
  62. LogInternal(const char *FilePath, int LineNumber, const char *CategoryName, log_severity Severity, const char *Format, ...)
  63. {
  64. lace_log_color Color;
  65. if(Severity == Info) Color = White;
  66. else if(Severity == Warning) Color = Red;
  67. else if(Severity == Error) Color = Yellow;
  68. else Color = Normal;
  69.  
  70. char Formated[1024 * 8];
  71.  
  72. va_list Arguments;
  73. va_start(Arguments, Format);
  74. rrvsprintf(Formated, Format, Arguments);
  75. va_end(Arguments);
  76.  
  77. char ToLog[1024 * 16];
  78. if(Severity == Error)
  79. {
  80. rrsprintf(ToLog, "%s:%i: %s:%s\n", FilePath, LineNumber, CategoryName, Formated);
  81. }
  82. else
  83. {
  84. rrsprintf(ToLog, "%s: %s\n", CategoryName, Formated);
  85. }
  86.  
  87.  
  88. OutputDebugStringWithColor(ToLog, Color);
  89. Platform.WriteToLog(ToLog);
  90.  
  91. if(Severity == Error)
  92. {
  93. PopMessageBox("Fatal Error", "");
  94. PostApplicationExit();
  95. }
  96. }
  97.  
  98.  
  99. #endif // LACE_LOG_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement