b3Logging.h 2.3 KB

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