summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2015-09-01 22:48:51 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2015-09-01 22:48:51 +0200
commit1af58bb8886673ac115f019094853fa763e79187 (patch)
treec2ab030898e74288f82c557287272546a990e932 /src/error.h
Initial commit.
Diffstat (limited to 'src/error.h')
-rw-r--r--src/error.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/error.h b/src/error.h
new file mode 100644
index 0000000..aa85e63
--- /dev/null
+++ b/src/error.h
@@ -0,0 +1,123 @@
+#ifndef RELABSD_ERROR_H
+#define RELABSD_ERROR_H
+
+#include <stdio.h>
+
+#include "config.h"
+#include "pervasive.h"
+
+#define _HIGHEST_DEBUG_LVL 100
+
+#define _DEBUG_LVL _HIGHEST_DEBUG_LVL
+#define _ENABLE_WARNINGS_OUTPUT 1
+#define _ENABLE_RUNTIME_ERRORS_OUTPUT 1
+#define _ENABLE_PROGRAMMING_ERRORS_OUTPUT 1
+#define _ENABLE_FATAL_ERROR_OUTPUT 1
+#define _ENABLE_ERROR_LOCATION 0
+
+#if _ENABLE_ERROR_LOCATION
+ #define _LOCATION "[" __FILE__ "][" _TO_STRING(__LINE__) "]"
+#else
+ #define _LOCATION ""
+#endif
+
+#define _PRINT_STDERR(symbol, str, ...)\
+ fprintf(stderr, "[" symbol "]" _LOCATION " " str "\n", __VA_ARGS__);
+
+#define _DEBUG(level, str, ...)\
+ _ISOLATE\
+ (\
+ if (level < _DEBUG_LVL)\
+ {\
+ _PRINT_STDERR("D", str, __VA_ARGS__);\
+ }\
+ )
+
+
+#define _WARNING(str, ...)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_WARNINGS_OUTPUT)\
+ {\
+ _PRINT_STDERR("W", str, __VA_ARGS__);\
+ }\
+ )
+
+#define _ERROR(str, ...)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_RUNTIME_ERRORS_OUTPUT)\
+ {\
+ _PRINT_STDERR("E", str, __VA_ARGS__);\
+ }\
+ )
+
+#define _PROG_ERROR(str, ...)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\
+ {\
+ _PRINT_STDERR("P", str, __VA_ARGS__);\
+ }\
+ )
+
+#define _FATAL(str, ...)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_FATAL_ERROR_OUTPUT)\
+ {\
+ _PRINT_STDERR("F", str, __VA_ARGS__);\
+ }\
+ )
+
+/* For outputs without dynamic content (static). ******************************/
+
+#define _PRINT_S_STDERR(symbol, str)\
+ fprintf(stderr, "[" symbol "]" _LOCATION " " str "\n");
+
+#define _S_DEBUG(level, str)\
+ _ISOLATE\
+ (\
+ if (level < _DEBUG_LVL)\
+ {\
+ _PRINT_S_STDERR("D", str);\
+ }\
+ )
+
+#define _S_WARNING(str)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_WARNINGS_OUTPUT)\
+ {\
+ _PRINT_S_STDERR("W", str);\
+ }\
+ )
+
+#define _S_ERROR(str)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_RUNTIME_ERRORS_OUTPUT)\
+ {\
+ _PRINT_S_STDERR("E", str);\
+ }\
+ )
+
+#define _S_PROG_ERROR(str)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\
+ {\
+ _PRINT_S_STDERR("P", str);\
+ }\
+ )
+
+#define _S_FATAL(str)\
+ _ISOLATE\
+ (\
+ if (_ENABLE_FATAL_ERROR_OUTPUT)\
+ {\
+ _PRINT_S_STDERR("F", str);\
+ }\
+ )
+
+#endif