b3Logging.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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(...) do{ b3OutputWarningMessageVarArgsInternal("b3Warning[%s,%d]:\n", __FILE__, __LINE__);b3OutputWarningMessageVarArgsInternal(__VA_ARGS__);} while (0)
  15. #define b3Error(...)do {b3OutputErrorMessageVarArgsInternal("b3Error[%s,%d]:\n", __FILE__, __LINE__);b3OutputErrorMessageVarArgsInternal(__VA_ARGS__);} while (0)
  16. #ifndef B3_NO_PROFILE
  17. void b3EnterProfileZone(const char* name);
  18. void b3LeaveProfileZone();
  19. #ifdef __cplusplus
  20. class b3ProfileZone
  21. {
  22. public:
  23. b3ProfileZone(const char* name)
  24. {
  25. b3EnterProfileZone(name);
  26. }
  27. ~b3ProfileZone()
  28. {
  29. b3LeaveProfileZone();
  30. }
  31. };
  32. #define B3_PROFILE(name) b3ProfileZone __profile(name)
  33. #endif
  34. #else //B3_NO_PROFILE
  35. #define B3_PROFILE(name)
  36. #define b3StartProfile(a)
  37. #define b3StopProfile
  38. #endif //#ifndef B3_NO_PROFILE
  39. typedef void(b3PrintfFunc)(const char* msg);
  40. typedef void(b3WarningMessageFunc)(const char* msg);
  41. typedef void(b3ErrorMessageFunc)(const char* msg);
  42. typedef void(b3EnterProfileZoneFunc)(const char* msg);
  43. typedef void(b3LeaveProfileZoneFunc)();
  44. ///The developer can route b3Printf output using their own implementation
  45. void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc);
  46. void b3SetCustomWarningMessageFunc(b3WarningMessageFunc* warningMsgFunc);
  47. void b3SetCustomErrorMessageFunc(b3ErrorMessageFunc* errorMsgFunc);
  48. ///Set custom profile zone functions (zones can be nested)
  49. void b3SetCustomEnterProfileZoneFunc(b3EnterProfileZoneFunc* enterFunc);
  50. void b3SetCustomLeaveProfileZoneFunc(b3LeaveProfileZoneFunc* leaveFunc);
  51. ///Don't use those internal functions directly, use the b3Printf or b3SetCustomPrintfFunc instead (or warning/error version)
  52. void b3OutputPrintfVarArgsInternal(const char* str, ...);
  53. void b3OutputWarningMessageVarArgsInternal(const char* str, ...);
  54. void b3OutputErrorMessageVarArgsInternal(const char* str, ...);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif //B3_LOGGING_H