project_files/frontlib/util/logging.h
changeset 7275 15f722e0b96f
parent 7224 5143861c83bd
child 7314 6171f0bad318
--- a/project_files/frontlib/util/logging.h	Mon Jun 25 15:21:18 2012 +0200
+++ b/project_files/frontlib/util/logging.h	Wed Jun 27 18:02:45 2012 +0200
@@ -17,10 +17,27 @@
  */
 char* flib_format_ip(uint32_t numip);
 
-void flib_log_e(const char *fmt, ...);
-void flib_log_w(const char *fmt, ...);
-void flib_log_i(const char *fmt, ...);
-void flib_log_d(const char *fmt, ...);
+/**
+ * Evaluates the expression cond. If it is true, a formatted error will be logged.
+ * Returns true if an error is logged, false otherwise (i.e. the boolean value of the argument)
+ */
+#define log_e_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_ERROR, !(bool)(cond), __VA_ARGS__)
+#define log_w_if(cond, ...) _flib_fassert(__func__, FLIB_LOGLEVEL_WARNING, !(bool)(cond), __VA_ARGS__)
+
+/**
+ * Shorthand for some common error types
+ */
+#define log_badparams_if(cond) log_e_if(cond, "Invalid Parameters")
+#define log_oom_if(cond) log_e_if(cond, "Out of Memory")
+
+#define flib_log_e(...) _flib_flog(__func__, FLIB_LOGLEVEL_ERROR, __VA_ARGS__)
+#define flib_log_w(...) _flib_flog(__func__, FLIB_LOGLEVEL_WARNING, __VA_ARGS__)
+#define flib_log_i(...) _flib_flog(__func__, FLIB_LOGLEVEL_INFO, __VA_ARGS__)
+#define flib_log_d(...) _flib_flog(__func__, FLIB_LOGLEVEL_DEBUG, __VA_ARGS__)
+
+bool _flib_assert_params(const char *func, bool cond);
+bool _flib_fassert(const char *func, int level, bool cond, const char *fmt, ...);
+void _flib_flog(const char *func, int level, const char *fmt, ...);
 
 int flib_log_getLevel();
 void flib_log_setLevel(int level);