summaryrefslogtreecommitdiff
path: root/src/mesa/main/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/errors.c')
-rw-r--r--src/mesa/main/errors.c72
1 files changed, 23 insertions, 49 deletions
diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index a4029c0896c..c42696074b3 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -35,14 +35,12 @@
#include "context.h"
#include "debug_output.h"
-
-
-static FILE *LogFile = NULL;
-
+#include "util/detect_os.h"
+#include "util/log.h"
+#include "api_exec_decl.h"
static void
-output_if_debug(const char *prefixString, const char *outputString,
- GLboolean newline)
+output_if_debug(enum mesa_log_level level, const char *outputString)
{
static int debug = -1;
@@ -51,14 +49,6 @@ output_if_debug(const char *prefixString, const char *outputString,
* by now so MESA_DEBUG_FLAGS will be initialized.
*/
if (debug == -1) {
- /* If MESA_LOG_FILE env var is set, log Mesa errors, warnings,
- * etc to the named file. Otherwise, output to stderr.
- */
- const char *logFile = getenv("MESA_LOG_FILE");
- if (logFile)
- LogFile = fopen(logFile, "w");
- if (!LogFile)
- LogFile = stderr;
#ifndef NDEBUG
/* in debug builds, print messages unless MESA_DEBUG="silent" */
if (MESA_DEBUG_FLAGS & DEBUG_SILENT)
@@ -72,28 +62,8 @@ output_if_debug(const char *prefixString, const char *outputString,
}
/* Now only print the string if we're required to do so. */
- if (debug) {
- if (prefixString)
- fprintf(LogFile, "%s: %s", prefixString, outputString);
- else
- fprintf(LogFile, "%s", outputString);
- if (newline)
- fprintf(LogFile, "\n");
- fflush(LogFile);
-
-#if defined(_WIN32)
- /* stderr from windows applications without console is not usually
- * visible, so communicate with the debugger instead */
- {
- char buf[4096];
- if (prefixString)
- snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
- else
- snprintf(buf, sizeof(buf), "%s%s", outputString, newline ? "\n" : "");
- OutputDebugStringA(buf);
- }
-#endif
- }
+ if (debug)
+ mesa_log(level, "Mesa", "%s", outputString);
}
@@ -104,8 +74,7 @@ output_if_debug(const char *prefixString, const char *outputString,
FILE *
_mesa_get_log_file(void)
{
- assert(LogFile);
- return LogFile;
+ return mesa_log_get_file();
}
@@ -123,7 +92,7 @@ flush_delayed_errors( struct gl_context *ctx )
ctx->ErrorDebugCount,
_mesa_enum_to_string(ctx->ErrorValue));
- output_if_debug("Mesa", s, GL_TRUE);
+ output_if_debug(MESA_LOG_ERROR, s);
ctx->ErrorDebugCount = 0;
}
@@ -132,7 +101,7 @@ flush_delayed_errors( struct gl_context *ctx )
/**
* Report a warning (a recoverable error condition) to stderr if
- * either DEBUG is defined or the MESA_DEBUG env var is set.
+ * either MESA_DEBUG is defined to 1 or the MESA_DEBUG env var is set.
*
* \param ctx GL context.
* \param fmtString printf()-like format string.
@@ -149,7 +118,7 @@ _mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
if (ctx)
flush_delayed_errors( ctx );
- output_if_debug("Mesa warning", str, GL_TRUE);
+ output_if_debug(MESA_LOG_WARN, str);
}
@@ -274,7 +243,7 @@ _mesa_gl_debug(struct gl_context *ctx,
/* limit the message to fit within KHR_debug buffers */
char s[MAX_DEBUG_MESSAGE_LENGTH];
- strncpy(s, msg, MAX_DEBUG_MESSAGE_LENGTH);
+ strncpy(s, msg, MAX_DEBUG_MESSAGE_LENGTH - 1);
s[MAX_DEBUG_MESSAGE_LENGTH - 1] = '\0';
len = MAX_DEBUG_MESSAGE_LENGTH - 1;
_mesa_log_msg(ctx, source, type, *id, severity, len, s);
@@ -288,7 +257,7 @@ _mesa_gl_debug(struct gl_context *ctx,
* Record an OpenGL state error. These usually occur when the user
* passes invalid parameters to a GL function.
*
- * If debugging is enabled (either at compile-time via the DEBUG macro, or
+ * If debugging is enabled (either at compile-time via the MESA_DEBUG macro, or
* run-time via the MESA_DEBUG environment variable), report the error with
* _mesa_debug().
*
@@ -349,7 +318,7 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
/* Print the error to stderr if needed. */
if (do_output) {
- output_if_debug("Mesa: User error", s2, GL_TRUE);
+ output_if_debug(MESA_LOG_ERROR, s2);
}
/* Log the error via ARB_debug_output if needed.*/
@@ -372,8 +341,8 @@ _mesa_error_no_memory(const char *caller)
}
/**
- * Report debug information. Print error message to stderr via fprintf().
- * No-op if DEBUG mode not enabled.
+ * Report debug information. Print error message to stderr via fprintf()
+ * when debug mode is enabled by NDEBUG; otherwise no-op.
*
* \param ctx GL context.
* \param fmtString printf()-style format string, followed by optional args.
@@ -387,8 +356,8 @@ _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
va_start(args, fmtString);
vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
- output_if_debug("Mesa", s, GL_FALSE);
-#endif /* DEBUG */
+ output_if_debug(MESA_LOG_DEBUG, s);
+#endif /* !NDEBUG */
(void) ctx;
(void) fmtString;
}
@@ -402,9 +371,14 @@ _mesa_log(const char *fmtString, ...)
va_start(args, fmtString);
vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
va_end(args);
- output_if_debug(NULL, s, GL_FALSE);
+ output_if_debug(MESA_LOG_INFO, s);
}
+void
+_mesa_log_direct(const char *string)
+{
+ output_if_debug(MESA_LOG_INFO, string);
+}
/**
* Report debug information from the shader compiler via GL_ARB_debug_output.