improve debug output
[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 <string>
8
9 // #include <lib/gui/emessage.h>
10
11 #ifdef MEMLEAK_CHECK
12 AllocList *allocList;
13 pthread_mutex_t memLock =
14         PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
15 #else
16         #include <lib/base/elock.h>
17 #endif
18
19 int infatal=0;
20
21 Signal2<void, int, const std::string&> logOutput;
22 int logOutputConsole=1;
23
24 void eFatal(const char* fmt, ...)
25 {
26         char buf[1024];
27         va_list ap;
28         va_start(ap, fmt);
29         vsnprintf(buf, 1024, fmt, ap);
30         va_end(ap);
31         logOutput(lvlFatal, buf);
32         fprintf(stderr, "FATAL: %s\n",buf );
33 #if 0
34         if (!infatal)
35         {
36                 infatal=1;
37                 eMessageBox msg(buf, "FATAL ERROR", eMessageBox::iconError|eMessageBox::btOK);
38                 msg.show();
39                 msg.exec();
40         }
41 #endif
42
43         _exit(0);
44 }
45
46 #ifdef DEBUG
47 void eDebug(const char* fmt, ...)
48 {
49         char buf[1024];
50         va_list ap;
51         va_start(ap, fmt);
52         vsnprintf(buf, 1024, fmt, ap);
53         va_end(ap);
54         logOutput(lvlDebug, std::string(buf) + "\n");
55         if (logOutputConsole)
56                 fprintf(stderr, "%s\n", buf);
57 }
58
59 void eDebugNoNewLine(const char* fmt, ...)
60 {
61         char buf[1024];
62         va_list ap;
63         va_start(ap, fmt);
64         vsnprintf(buf, 1024, fmt, ap);
65         va_end(ap);
66         logOutput(lvlDebug, buf);
67         if (logOutputConsole)
68                 fprintf(stderr, "%s", buf);
69 }
70
71 void eWarning(const char* fmt, ...)
72 {
73         char buf[1024];
74         va_list ap;
75         va_start(ap, fmt);
76         vsnprintf(buf, 1024, fmt, ap);
77         va_end(ap);
78         logOutput(lvlWarning, std::string(buf) + "\n");
79         if (logOutputConsole)
80                 fprintf(stderr, "%s\n", buf);
81 }
82 #endif // DEBUG