- eConnections holds reference to object
[enigma2.git] / lib / base / eerror.cpp
1 #include <lib/base/eerror.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6
7 #include <lib/gui/emessage.h>
8
9 int infatal=0;
10
11 Signal2<void, int, const eString&> logOutput;
12 int logOutputConsole=1;
13
14 void eFatal(const char* fmt, ...)
15 {
16         char buf[1024];
17         va_list ap;
18         va_start(ap, fmt);
19         vsnprintf(buf, 1024, fmt, ap);
20         va_end(ap);
21         logOutput(lvlFatal, buf);
22         fprintf(stderr, "%s\n",buf );
23         if (!infatal)
24         {
25                 infatal=1;
26                 eMessageBox msg(buf, "FATAL ERROR", eMessageBox::iconError|eMessageBox::btOK);
27                 msg.show();
28                 msg.exec();
29         }
30         _exit(0);
31 }
32
33 #ifdef DEBUG
34 void eDebug(const char* fmt, ...)
35 {
36         char buf[1024];
37         va_list ap;
38         va_start(ap, fmt);
39         vsnprintf(buf, 1024, fmt, ap);
40         va_end(ap);
41         logOutput(lvlDebug, eString(buf) + "\n");
42         if (logOutputConsole)
43                 fprintf(stderr, "%s\n", buf);
44 }
45
46 void eDebugNoNewLine(const char* fmt, ...)
47 {
48         char buf[1024];
49         va_list ap;
50         va_start(ap, fmt);
51         vsnprintf(buf, 1024, fmt, ap);
52         va_end(ap);
53         logOutput(lvlDebug, buf);
54         if (logOutputConsole)
55                 fprintf(stderr, "%s", buf);
56 }
57
58 void eWarning(const char* fmt, ...)
59 {
60         char buf[1024];
61         va_list ap;
62         va_start(ap, fmt);
63         vsnprintf(buf, 1024, fmt, ap);
64         va_end(ap);
65         logOutput(lvlWarning, eString(buf) + "\n");
66         if (logOutputConsole)
67                 fprintf(stderr, "%s\n", buf);
68 }
69 #endif // DEBUG