2
0

b3Logging.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef B3_LOGGING_H
  2. #define B3_LOGGING_H
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. ///We add the do/while so that the statement "if (condition) b3Printf("test"); else {...}" would fail
  8. ///You can also customize the message by uncommenting out a different line below
  9. #define b3Printf(...) b3OutputPrintfVarArgsInternal(__VA_ARGS__)
  10. //#define b3Printf(...) do {b3OutputPrintfVarArgsInternal("b3Printf[%s,%d]:",__FILE__,__LINE__);b3OutputPrintfVarArgsInternal(__VA_ARGS__); } while(0)
  11. //#define b3Printf b3OutputPrintfVarArgsInternal
  12. //#define b3Printf(...) printf(__VA_ARGS__)
  13. //#define b3Printf(...)
  14. #define b3Warning(...) \
  15. do \
  16. { \
  17. b3OutputWarningMessageVarArgsInternal("b3Warning[%s,%d]:\n", __FILE__, __LINE__); \
  18. b3OutputWarningMessageVarArgsInternal(__VA_ARGS__); \
  19. } while (0)
  20. #define b3Error(...) \
  21. do \
  22. { \
  23. b3OutputErrorMessageVarArgsInternal("b3Error[%s,%d]:\n", __FILE__, __LINE__); \
  24. b3OutputErrorMessageVarArgsInternal(__VA_ARGS__); \
  25. } while (0)
  26. #ifndef B3_NO_PROFILE
  27. void b3EnterProfileZone(const char* name);
  28. void b3LeaveProfileZone();
  29. #ifdef __cplusplus
  30. class b3ProfileZone
  31. {
  32. public:
  33. b3ProfileZone(const char* name)
  34. {
  35. b3EnterProfileZone(name);
  36. }
  37. ~b3ProfileZone()
  38. {
  39. b3LeaveProfileZone();
  40. }
  41. };
  42. #define B3_PROFILE(name) b3ProfileZone __profile(name)
  43. #endif
  44. #else //B3_NO_PROFILE
  45. #define B3_PROFILE(name)
  46. #define b3StartProfile(a)
  47. #define b3StopProfile
  48. #endif //#ifndef B3_NO_PROFILE
  49. typedef void(b3PrintfFunc)(const char* msg);
  50. typedef void(b3WarningMessageFunc)(const char* msg);
  51. typedef void(b3ErrorMessageFunc)(const char* msg);
  52. typedef void(b3EnterProfileZoneFunc)(const char* msg);
  53. typedef void(b3LeaveProfileZoneFunc)();
  54. ///The developer can route b3Printf output using their own implementation
  55. void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc);
  56. void b3SetCustomWarningMessageFunc(b3WarningMessageFunc* warningMsgFunc);
  57. void b3SetCustomErrorMessageFunc(b3ErrorMessageFunc* errorMsgFunc);
  58. ///Set custom profile zone functions (zones can be nested)
  59. void b3SetCustomEnterProfileZoneFunc(b3EnterProfileZoneFunc* enterFunc);
  60. void b3SetCustomLeaveProfileZoneFunc(b3LeaveProfileZoneFunc* leaveFunc);
  61. ///Don't use those internal functions directly, use the b3Printf or b3SetCustomPrintfFunc instead (or warning/error version)
  62. void b3OutputPrintfVarArgsInternal(const char* str, ...);
  63. void b3OutputWarningMessageVarArgsInternal(const char* str, ...);
  64. void b3OutputErrorMessageVarArgsInternal(const char* str, ...);
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif //B3_LOGGING_H