summaryrefslogtreecommitdiffstats
path: root/src/egl/main/egllog.c
blob: 59b1d2684e3c44d802deaaf57f6e181a4e2efce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()? */
      }
   }
}