aboutsummaryrefslogtreecommitdiff
path: root/lib/base/eerror.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/base/eerror.cpp')
-rw-r--r--lib/base/eerror.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/base/eerror.cpp b/lib/base/eerror.cpp
new file mode 100644
index 00000000..0871bb71
--- /dev/null
+++ b/lib/base/eerror.cpp
@@ -0,0 +1,69 @@
+#include <lib/base/eerror.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <lib/gui/emessage.h>
+
+int infatal=0;
+
+Signal2<void, int, const eString&> logOutput;
+int logOutputConsole=1;
+
+void eFatal(const char* fmt, ...)
+{
+ char buf[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf, 1024, fmt, ap);
+ va_end(ap);
+ logOutput(lvlFatal, buf);
+ fprintf(stderr, "%s\n",buf );
+ if (!infatal)
+ {
+ infatal=1;
+ eMessageBox msg(buf, "FATAL ERROR", eMessageBox::iconError|eMessageBox::btOK);
+ msg.show();
+ msg.exec();
+ }
+ _exit(0);
+}
+
+#ifdef DEBUG
+void eDebug(const char* fmt, ...)
+{
+ char buf[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf, 1024, fmt, ap);
+ va_end(ap);
+ logOutput(lvlDebug, eString(buf) + "\n");
+ if (logOutputConsole)
+ fprintf(stderr, "%s\n", buf);
+}
+
+void eDebugNoNewLine(const char* fmt, ...)
+{
+ char buf[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf, 1024, fmt, ap);
+ va_end(ap);
+ logOutput(lvlDebug, buf);
+ if (logOutputConsole)
+ fprintf(stderr, "%s", buf);
+}
+
+void eWarning(const char* fmt, ...)
+{
+ char buf[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(buf, 1024, fmt, ap);
+ va_end(ap);
+ logOutput(lvlWarning, eString(buf) + "\n");
+ if (logOutputConsole)
+ fprintf(stderr, "%s\n", buf);
+}
+#endif // DEBUG