2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
#ifndef B3_LOGGING_H
|
|
|
|
#define B3_LOGGING_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2019-01-03 13:26:51 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-08-01 12:30:58 +00:00
|
|
|
#endif
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
///We add the do/while so that the statement "if (condition) b3Printf("test"); else {...}" would fail
|
|
|
|
///You can also customize the message by uncommenting out a different line below
|
|
|
|
#define b3Printf(...) b3OutputPrintfVarArgsInternal(__VA_ARGS__)
|
2019-01-03 13:26:51 +00:00
|
|
|
//#define b3Printf(...) do {b3OutputPrintfVarArgsInternal("b3Printf[%s,%d]:",__FILE__,__LINE__);b3OutputPrintfVarArgsInternal(__VA_ARGS__); } while(0)
|
|
|
|
//#define b3Printf b3OutputPrintfVarArgsInternal
|
|
|
|
//#define b3Printf(...) printf(__VA_ARGS__)
|
|
|
|
//#define b3Printf(...)
|
2020-01-08 17:05:43 +00:00
|
|
|
#define b3Warning(...) do{ b3OutputWarningMessageVarArgsInternal("b3Warning[%s,%d]:\n", __FILE__, __LINE__);b3OutputWarningMessageVarArgsInternal(__VA_ARGS__);} while (0)
|
|
|
|
#define b3Error(...)do {b3OutputErrorMessageVarArgsInternal("b3Error[%s,%d]:\n", __FILE__, __LINE__);b3OutputErrorMessageVarArgsInternal(__VA_ARGS__);} while (0)
|
2017-08-01 12:30:58 +00:00
|
|
|
#ifndef B3_NO_PROFILE
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void b3EnterProfileZone(const char* name);
|
|
|
|
void b3LeaveProfileZone();
|
2017-08-01 12:30:58 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
class b3ProfileZone
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
b3ProfileZone(const char* name)
|
|
|
|
{
|
|
|
|
b3EnterProfileZone(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
~b3ProfileZone()
|
|
|
|
{
|
|
|
|
b3LeaveProfileZone();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define B3_PROFILE(name) b3ProfileZone __profile(name)
|
2017-08-01 12:30:58 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#else //B3_NO_PROFILE
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#define B3_PROFILE(name)
|
2017-08-01 12:30:58 +00:00
|
|
|
#define b3StartProfile(a)
|
|
|
|
#define b3StopProfile
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //#ifndef B3_NO_PROFILE
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
typedef void(b3PrintfFunc)(const char* msg);
|
|
|
|
typedef void(b3WarningMessageFunc)(const char* msg);
|
|
|
|
typedef void(b3ErrorMessageFunc)(const char* msg);
|
|
|
|
typedef void(b3EnterProfileZoneFunc)(const char* msg);
|
|
|
|
typedef void(b3LeaveProfileZoneFunc)();
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
///The developer can route b3Printf output using their own implementation
|
|
|
|
void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc);
|
|
|
|
void b3SetCustomWarningMessageFunc(b3WarningMessageFunc* warningMsgFunc);
|
|
|
|
void b3SetCustomErrorMessageFunc(b3ErrorMessageFunc* errorMsgFunc);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
///Set custom profile zone functions (zones can be nested)
|
|
|
|
void b3SetCustomEnterProfileZoneFunc(b3EnterProfileZoneFunc* enterFunc);
|
|
|
|
void b3SetCustomLeaveProfileZoneFunc(b3LeaveProfileZoneFunc* leaveFunc);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
///Don't use those internal functions directly, use the b3Printf or b3SetCustomPrintfFunc instead (or warning/error version)
|
|
|
|
void b3OutputPrintfVarArgsInternal(const char* str, ...);
|
|
|
|
void b3OutputWarningMessageVarArgsInternal(const char* str, ...);
|
|
|
|
void b3OutputErrorMessageVarArgsInternal(const char* str, ...);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
2017-08-01 12:30:58 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //B3_LOGGING_H
|