The attached patch allows to set the EGL log level at runtime using
environment variables.

-- 
Christian Neumair <[EMAIL PROTECTED]>
Index: src/egl/main/egllog.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/egl/main/egllog.c,v
retrieving revision 1.1
diff -u -p -r1.1 egllog.c
--- src/egl/main/egllog.c	23 Nov 2005 01:37:30 -0000	1.1
+++ src/egl/main/egllog.c	16 Dec 2006 17:04:16 -0000
@@ -6,14 +6,38 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "egllog.h"
 
 #define MAXSTRING 1000
+#define EGL_FALLBACK_LOG_LEVEL      _EGL_DEBUG
+#define EGL_FALLBACK_LOG_LEVEL_STR  "debug"
 
+static EGLint ReportingLevel = -1;
 
-/* XXX init this with an env var or something */
-static EGLint ReportingLevel = _EGL_DEBUG;
+static void
+log_level_initialize (void)
+{
+	char *log_env = getenv ("EGL_LOG_LEVEL");
 
+	if (log_env == NULL) {
+		ReportingLevel = EGL_FALLBACK_LOG_LEVEL;
+	} else if (strcasecmp (log_env, "fatal") == 0) {
+		ReportingLevel = _EGL_FATAL;
+	} else if (strcasecmp (log_env, "warning") == 0) {
+		ReportingLevel = _EGL_WARNING;
+	} else if (strcasecmp (log_env, "info") == 0) {
+		ReportingLevel = _EGL_INFO;
+	} else if (strcasecmp (log_env, "debug") == 0) {
+		ReportingLevel = _EGL_DEBUG;
+	} else {
+		fprintf (stderr, "Unrecognized EGL_LOG_LEVEL environment variable value. "
+				 "Expected one of \"fatal\", \"warning\", \"info\", \"debug\". "
+				 "Got \"%s\". Falling back to \"%s\".\n",
+				 log_env, EGL_FALLBACK_LOG_LEVEL_STR);
+		ReportingLevel = EGL_FALLBACK_LOG_LEVEL;
+	}
+}
 
 /**
  * Log a message to stderr.
@@ -25,6 +49,12 @@ _eglLog(EGLint level, const char *fmtStr
    va_list args;
    char msg[MAXSTRING];
    const char *levelStr;
+   static int log_level_initialized = 0;
+
+   if (!log_level_initialized) {
+	log_level_initialize ();
+	log_level_initialized = 1;
+   }
 
    if (level <= ReportingLevel) {
       switch (level) {
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to