42 */ |
42 */ |
43 #define log_e_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_ERROR, !(bool)(cond), __VA_ARGS__) |
43 #define log_e_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_ERROR, !(bool)(cond), __VA_ARGS__) |
44 #define log_w_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_WARNING, !(bool)(cond), __VA_ARGS__) |
44 #define log_w_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_WARNING, !(bool)(cond), __VA_ARGS__) |
45 |
45 |
46 /** |
46 /** |
47 * Shorthand for some common error types |
47 * Helper macros for log_badargs_if |
|
48 * The t parameters are the textual representation of the c parameters. They need to be passed |
|
49 * explicitly, to prevent them from being expanded in prescan. |
48 */ |
50 */ |
49 #define log_badparams_if(cond) log_e_if(cond, "Invalid Parameters") |
51 #define _flib_lbi(c1,t1) log_e_if(c1, "Invalid Argument (%s)", t1) |
|
52 #define _flib_lbi2(c1,t1,c2,t2) (_flib_lbi(c1,t1) || _flib_lbi(c2,t2)) |
|
53 #define _flib_lbi3(c1,t1,c2,t2,c3,t3) (_flib_lbi(c1,t1) || _flib_lbi2(c2,t2,c3,t3)) |
|
54 #define _flib_lbi4(c1,t1,c2,t2,c3,t3,c4,t4) (_flib_lbi(c1,t1) || _flib_lbi3(c2,t2,c3,t3,c4,t4)) |
|
55 #define _flib_lbi5(c1,t1,c2,t2,c3,t3,c4,t4,c5,t5) (_flib_lbi(c1,t1) || _flib_lbi4(c2,t2,c3,t3,c4,t4,c5,t5)) |
|
56 #define _flib_lbi6(c1,t1,c2,t2,c3,t3,c4,t4,c5,t5,c6,t6) (_flib_lbi(c1,t1) || _flib_lbi5(c2,t2,c3,t3,c4,t4,c5,t5,c6,t6)) |
|
57 |
|
58 /** |
|
59 * These macros log an "Invalid Argument" error for the first of their arguments that evaluates to true. |
|
60 * The text of the argument is included in the log message. |
|
61 * The expression returns true if any of its arguments is true (i.e. if an argument error was logged). |
|
62 * |
|
63 * For example, log_badargs_if(x==NULL) will log "Invalid Argument (x==NULL)" and return true if x is NULL. |
|
64 */ |
|
65 #define log_badargs_if(c1) _flib_lbi(c1,#c1) |
|
66 #define log_badargs_if2(c1, c2) _flib_lbi2(c1,#c1,c2,#c2) |
|
67 #define log_badargs_if3(c1, c2, c3) _flib_lbi3(c1,#c1,c2,#c2,c3,#c3) |
|
68 #define log_badargs_if4(c1, c2, c3, c4) _flib_lbi4(c1,#c1,c2,#c2,c3,#c3,c4,#c4) |
|
69 #define log_badargs_if5(c1, c2, c3, c4, c5) _flib_lbi5(c1,#c1,c2,#c2,c3,#c3,c4,#c4,c5,#c5) |
|
70 #define log_badargs_if6(c1, c2, c3, c4, c5, c6) _flib_lbi6(c1,#c1,c2,#c2,c3,#c3,c4,#c4,c5,#c5,c6,#c6) |
|
71 |
50 #define log_oom_if(cond) log_e_if(cond, "Out of Memory") |
72 #define log_oom_if(cond) log_e_if(cond, "Out of Memory") |
51 |
73 |
52 #define flib_log_e(...) _flib_flog(__func__, FLIB_LOGLEVEL_ERROR, __VA_ARGS__) |
74 #define flib_log_e(...) _flib_flog(__func__, FLIB_LOGLEVEL_ERROR, __VA_ARGS__) |
53 #define flib_log_w(...) _flib_flog(__func__, FLIB_LOGLEVEL_WARNING, __VA_ARGS__) |
75 #define flib_log_w(...) _flib_flog(__func__, FLIB_LOGLEVEL_WARNING, __VA_ARGS__) |
54 #define flib_log_i(...) _flib_flog(__func__, FLIB_LOGLEVEL_INFO, __VA_ARGS__) |
76 #define flib_log_i(...) _flib_flog(__func__, FLIB_LOGLEVEL_INFO, __VA_ARGS__) |
55 #define flib_log_d(...) _flib_flog(__func__, FLIB_LOGLEVEL_DEBUG, __VA_ARGS__) |
77 #define flib_log_d(...) _flib_flog(__func__, FLIB_LOGLEVEL_DEBUG, __VA_ARGS__) |
56 |
78 |
57 bool _flib_assert_params(const char *func, bool cond); |
|
58 bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...); |
79 bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...); |
59 void _flib_flog(const char *func, int level, const char *fmt, ...); |
80 void _flib_flog(const char *func, int level, const char *fmt, ...); |
60 |
81 |
61 int flib_log_getLevel(); |
82 int flib_log_getLevel(); |
62 void flib_log_setLevel(int level); |
83 void flib_log_setLevel(int level); |