2019-12-19 03:24:12 +00:00
|
|
|
#ifndef cwLOG_H
|
|
|
|
#define cwLOG_H
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
namespace log
|
2019-12-19 03:24:12 +00:00
|
|
|
{
|
2019-12-27 21:52:45 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
kInvalid_LogLevel,
|
2020-09-01 19:46:21 +00:00
|
|
|
kPrint_LogLevel,
|
2019-12-27 21:52:45 +00:00
|
|
|
kDebug_LogLevel,
|
|
|
|
kInfo_LogLevel,
|
|
|
|
kWarning_LogLevel,
|
|
|
|
kError_LogLevel,
|
|
|
|
kFatal_LogLevel,
|
|
|
|
} logLevelId_t;
|
|
|
|
|
2023-09-12 21:38:44 +00:00
|
|
|
enum {
|
|
|
|
kDateTimeFl = 0x01,
|
|
|
|
};
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
typedef handle<struct log_str> handle_t;
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
typedef void (*logOutputCbFunc_t)( void* cbArg, unsigned level, const char* text );
|
2023-09-12 21:38:44 +00:00
|
|
|
typedef void (*logFormatCbFunc_t)( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned flags, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* msg );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
rc_t create( handle_t& hRef, unsigned level=kDebug_LogLevel, logOutputCbFunc_t outCb=nullptr, void* outCbArg=nullptr, logFormatCbFunc_t fmtCb=nullptr, void* fmtCbArg=nullptr );
|
|
|
|
rc_t destroy( handle_t& hRef );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
rc_t msg( handle_t h, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* fmt, va_list vl );
|
|
|
|
rc_t msg( handle_t h, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* fmt, ... );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
void setLevel( handle_t h, unsigned level );
|
|
|
|
unsigned level( handle_t h );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2021-12-30 02:35:10 +00:00
|
|
|
void setOutputCb( handle_t h, logOutputCbFunc_t outFunc, void* outCbArg );
|
|
|
|
void setFormatCb( handle_t h, logFormatCbFunc_t fmtFunc, void* fmtCbArg );
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
const char* levelToLabel( unsigned level );
|
2023-09-12 21:38:44 +00:00
|
|
|
|
|
|
|
unsigned flags( handle_t h );
|
|
|
|
void set_flags( handle_t h, unsigned flags );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
void defaultOutput( void* arg, unsigned level, const char* text );
|
2023-09-12 21:38:44 +00:00
|
|
|
void defaultFormatter( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned flags, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* msg );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
rc_t createGlobal( unsigned level=kDebug_LogLevel, logOutputCbFunc_t outCb=nullptr, void* outCbArg=nullptr, logFormatCbFunc_t fmtCb=nullptr, void* fmtCbArg=nullptr );
|
|
|
|
rc_t destroyGlobal( );
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
void setGlobalHandle( handle_t h );
|
|
|
|
handle_t globalHandle();
|
|
|
|
}
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVDebugH(h,rc,fmt, vl) cw::log::msg( h, cw::log::kDebug_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, vl )
|
|
|
|
#define cwLogDebugH( h,rc,fmt,...) cw::log::msg( h, cw::log::kDebug_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2020-09-01 19:46:21 +00:00
|
|
|
#define cwLogVPrintH(h,fmt, vl) cw::log::msg( h, cw::log::kPrint_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, cw::kOkRC, fmt, vl )
|
|
|
|
#define cwLogPrintH( h,fmt,...) cw::log::msg( h, cw::log::kPrint_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, cw::kOkRC, fmt, ##__VA_ARGS__ )
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVInfoH(h,fmt, vl) cw::log::msg( h, cw::log::kInfo_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, cw::kOkRC, fmt, vl )
|
|
|
|
#define cwLogInfoH( h,fmt,...) cw::log::msg( h, cw::log::kInfo_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, cw::kOkRC, fmt, ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVWarningH(h,rc,fmt, vl) cw::log::msg( h, cw::log::kWarning_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, vl )
|
|
|
|
#define cwLogWarningH( h,rc,fmt,...) cw::log::msg( h, cw::log::kWarning_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVErrorH(h,rc,fmt, vl) cw::log::msg( h, cw::log::kError_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, vl )
|
|
|
|
#define cwLogErrorH( h,rc,fmt,...) cw::log::msg( h, cw::log::kError_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVSysErrorH(h,rc,sysRc,fmt, vl) cw::log::msg( h, cw::log::kError_LogLevel, __FUNCTION__, __FILE__, __LINE__, sysRc, rc, fmt, vl )
|
|
|
|
#define cwLogSysErrorH( h,rc,sysRc,fmt,...) cw::log::msg( h, cw::log::kError_LogLevel, __FUNCTION__, __FILE__, __LINE__, sysRc, rc, fmt, ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVFatalH(h,rc,fmt, vl) cw::log::msg( h, cw::log::kFatal_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, vl )
|
|
|
|
#define cwLogFatalH( h,rc,fmt,...) cw::log::msg( h, cw::log::kFatal_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, rc, fmt, ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
#ifdef cwLOG_DEBUG
|
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVDebugRC(rc,fmt, vl) cwLogVDebugH( cw::log::globalhandle(), (rc), (fmt), (vl) )
|
|
|
|
#define cwLogDebugRC( rc,fmt,...) cwLogDebugH( cw::log::globalHandle(), (rc), (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVDebug(fmt, vl) cwLogVDebugH( cw::log::globalHandle(), cw::kOkRC, (fmt), (vl) )
|
|
|
|
#define cwLogDebug( fmt,...) cwLogDebugH( cw::log::globalHandle(), cw::kOkRC, (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define cwLogVDebugRC(rc,fmt, vl)
|
|
|
|
#define cwLogDebugRC( rc,fmt,...)
|
|
|
|
|
|
|
|
#define cwLogVDebug(fmt, vl)
|
|
|
|
#define cwLogDebug( fmt,...)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-09-01 19:46:21 +00:00
|
|
|
#define cwLogVPrint(fmt, vl) cwLogVPrintH( cw::log::globalHandle(), (fmt), (vl) )
|
|
|
|
#define cwLogPrint( fmt,...) cwLogPrintH( cw::log::globalHandle(), (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVInfo(fmt, vl) cwLogVInfoH( cw::log::globalHandle(), (fmt), (vl) )
|
|
|
|
#define cwLogInfo( fmt,...) cwLogInfoH( cw::log::globalHandle(), (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVWarningRC(rc,fmt, vl) cwLogVWarningH( cw::log::globalHandle(), (rc), (fmt), (vl) )
|
|
|
|
#define cwLogWarningRC( rc,fmt,...) cwLogWarningH( cw::log::globalHandle(), (rc), (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVWarning(fmt, vl) cwLogVWarningH( cw::log::globalHandle(), cw::kOkRC, (fmt), (vl) )
|
|
|
|
#define cwLogWarning( fmt,...) cwLogWarningH( cw::log::globalHandle(), cw::kOkRC, (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVSysError(rc,sysRC,fmt, vl) cwLogVSysErrorH( cw::log::globalHandle(), (rc), (sysRC), (fmt), (vl) )
|
|
|
|
#define cwLogSysError( rc,sysRC,fmt,...) cwLogSysErrorH( cw::log::globalHandle(), (rc), (sysRC), (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVError(rc,fmt, vl) cwLogVErrorH( cw::log::globalHandle(), (rc), (fmt), (vl) )
|
|
|
|
#define cwLogError( rc,fmt,...) cwLogErrorH( cw::log::globalHandle(), (rc), (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
2019-12-27 21:52:45 +00:00
|
|
|
#define cwLogVFatal(rc,fmt, vl) cwLogVFatalH( cw::log::globalHandle(), (rc), (fmt), (vl) )
|
|
|
|
#define cwLogFatal( rc,fmt,...) cwLogFatalH( cw::log::globalHandle(), (rc), (fmt), ##__VA_ARGS__ )
|
2019-12-19 03:24:12 +00:00
|
|
|
|
|
|
|
|
2021-08-23 02:41:33 +00:00
|
|
|
// This log level is intended for debugging individual modules.
|
|
|
|
// By defining cwLOG_MODULE prior to cwLog.h in a given module these logging lines will be enabled.
|
|
|
|
#ifdef cwLOG_MODULE
|
|
|
|
|
2021-12-30 02:35:10 +00:00
|
|
|
#define cwLogVModRC(rc,fmt, vl) cw::log::msg( cw::log::globalHandle(), cw::log::kInfo_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, (rc), (fmt), (vl) )
|
|
|
|
#define cwLogModRC( rc,fmt,...) cw::log::msg( cw::log::globalHandle(), cw::log::kInfo_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, (rc), (fmt), ##__VA_ARGS__ )
|
2021-08-23 02:41:33 +00:00
|
|
|
|
2021-12-30 02:35:10 +00:00
|
|
|
#define cwLogVMod(fmt, vl) cw::log::msg( cw::log::globalHandle(), cw::log::kInfo_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, cw::kOkRC, (fmt), (vl) )
|
|
|
|
#define cwLogMod( fmt,...) cw::log::msg( cw::log::globalHandle(), cw::log::kInfo_LogLevel, __FUNCTION__, __FILE__, __LINE__, 0, cw::kOkRC, (fmt), ##__VA_ARGS__ )
|
2021-08-23 02:41:33 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define cwLogVModRC(rc,fmt, vl)
|
|
|
|
#define cwLogModRC( rc,fmt,...)
|
|
|
|
|
|
|
|
#define cwLogVMod(fmt, vl)
|
|
|
|
#define cwLogMod( fmt,...)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-19 03:24:12 +00:00
|
|
|
#endif
|