Merge branch terrible and branch awful
[ipdf/code.git] / src / log.cpp
index 699036b..88c47b7 100644 (file)
@@ -10,6 +10,9 @@
 #include <cstdio>
 #include <unistd.h>
 #include <stdarg.h>
+#ifndef __MINGW32__
+#include <execinfo.h>
+#endif
 
 #ifdef LOG_SYSLOG
 
@@ -75,13 +78,13 @@ void LogEx(int level, const char * funct, const char * file, int line, ...)
                        severity = "WARNING";
                        break;
                case LOG_NOTICE:
-                       severity = "NOTICE";
+                       severity = "notice";
                        break;
                case LOG_INFO:
-                       severity = "INFO";
+                       severity = "info";
                        break;
                default:
-                       severity = "DEBUG";
+                       severity = "debug";
                        break;
        }
 
@@ -117,7 +120,6 @@ void FatalEx(const char * funct, const char * file, int line, ...)
                // Fatal error in the Fatal function.
                // (This really shouldn't happen unless someone does something insanely stupid)
                Fatal("Format string is NULL");
-               return; // Should never get here
        }
 
        vsnprintf(buffer, BUFSIZ, fmt,va);
@@ -139,3 +141,17 @@ void FatalEx(const char * funct, const char * file, int line, ...)
 }
 
 
+/**
+ * Print a backtrace
+ */
+void Backtrace(int size)
+{
+       #ifndef __MINGW32__
+       void * buffer[100];
+       int actual_size = backtrace(buffer, size);
+       backtrace_symbols_fd(buffer, actual_size, fileno(stderr));
+       #else
+               Error("Backtrace not supported by compiler");
+       #endif
+}
+

UCC git Repository :: git.ucc.asn.au