New _eglLog() function to replace fprintf/printf calls for debug/info.
authorBrian Paul <brian.paul@tungstengraphics.com>
Wed, 23 Nov 2005 01:37:30 +0000 (01:37 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Wed, 23 Nov 2005 01:37:30 +0000 (01:37 +0000)
src/egl/main/Makefile
src/egl/main/egllog.c [new file with mode: 0644]
src/egl/main/egllog.h [new file with mode: 0644]

index 4bb1ffc9e856bd6b46894277a96f500b895edbf4..45a4fb39b8b554fab237eb8cf6b619c69a6ae893 100644 (file)
@@ -12,6 +12,7 @@ HEADERS = \
        egldisplay.h \
        egldriver.h \
        eglglobals.h \
+       egllog.h \
        eglhash.h \
        eglmode.h \
        eglscreen.h \
@@ -24,6 +25,7 @@ SOURCES = \
        egldisplay.c \
        egldriver.c \
        eglglobals.c \
+       egllog.c \
        eglhash.c \
        eglmode.c \
        eglscreen.c \
diff --git a/src/egl/main/egllog.c b/src/egl/main/egllog.c
new file mode 100644 (file)
index 0000000..59b1d26
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * Logging facility for debug/info messages.
+ */
+
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "egllog.h"
+
+#define MAXSTRING 1000
+
+
+/* XXX init this with an env var or something */
+static EGLint ReportingLevel = _EGL_DEBUG;
+
+
+/**
+ * Log a message to stderr.
+ * \param level one of _EGL_FATAL, _EGL_WARNING, _EGL_INFO, _EGL_DEBUG.
+ */
+void
+_eglLog(EGLint level, const char *fmtStr, ...)
+{
+   va_list args;
+   char msg[MAXSTRING];
+   const char *levelStr;
+
+   if (level <= ReportingLevel) {
+      switch (level) {
+      case _EGL_FATAL:
+         levelStr = "Fatal";
+         break;
+      case _EGL_WARNING:
+         levelStr = "Warning";
+         break;
+      case _EGL_INFO:
+         levelStr = "Info";
+         break;
+      case _EGL_DEBUG:
+         levelStr = "Debug";
+         break;
+      default:
+         levelStr = "";
+      }
+
+      va_start(args, fmtStr);
+      vsnprintf(msg, MAXSTRING, fmtStr, args);
+      va_end(args);
+
+      fprintf(stderr, "EGL %s: %s\n", levelStr, msg);
+
+      if (level == _EGL_FATAL) {
+         exit(1); /* or abort()? */
+      }
+   }
+}
diff --git a/src/egl/main/egllog.h b/src/egl/main/egllog.h
new file mode 100644 (file)
index 0000000..2fa352f
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef EGLLOG_INCLUDED
+#define EGLLOG_INCLUDED
+
+#include "egltypedefs.h"
+
+#define _EGL_FATAL   0   /* unrecoverable error */
+#define _EGL_WARNING 1   /* recoverable error/problem */
+#define _EGL_INFO    2   /* just useful info */
+#define _EGL_DEBUG   3   /* useful info for debugging */
+
+
+extern void
+_eglLog(EGLint level, const char *fmtStr, ...);
+
+
+#endif /* EGLLOG_INCLUDED */