summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2012-04-28 23:19:42 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2012-05-03 10:58:34 -0700
commit51691f0767f6a75a1f549cd979a878a0ad12a228 (patch)
tree86685afa697ba08d558e26c86ba5880c53c547d1 /src
parentcf5db0a418b63d71385b43897a7ea9be7bb785d1 (diff)
darwin: Use ASL for logging
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
Diffstat (limited to 'src')
-rw-r--r--src/glx/apple/Makefile1
-rw-r--r--src/glx/apple/apple_glx.c25
-rw-r--r--src/glx/apple/apple_glx.h3
-rw-r--r--src/glx/apple/apple_glx_log.c118
-rw-r--r--src/glx/apple/apple_glx_log.h57
5 files changed, 183 insertions, 21 deletions
diff --git a/src/glx/apple/Makefile b/src/glx/apple/Makefile
index dc64295f73c..68fe6ad745b 100644
--- a/src/glx/apple/Makefile
+++ b/src/glx/apple/Makefile
@@ -26,6 +26,7 @@ SOURCES = \
apple_glx.c \
apple_glx_context.c \
apple_glx_drawable.c \
+ apple_glx_log.c \
apple_glx_pbuffer.c \
apple_glx_pixmap.c \
apple_glx_surface.c \
diff --git a/src/glx/apple/apple_glx.c b/src/glx/apple/apple_glx.c
index d94c1e0fb16..56cff64a15b 100644
--- a/src/glx/apple/apple_glx.c
+++ b/src/glx/apple/apple_glx.c
@@ -33,6 +33,8 @@
#include <assert.h>
#include <stdarg.h>
#include <dlfcn.h>
+#include <pthread.h>
+#include <inttypes.h>
#include "appledri.h"
#include "apple_glx.h"
#include "apple_glx_context.h"
@@ -43,22 +45,6 @@ static int dri_event_base = 0;
const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
-static bool diagnostic = false;
-
-void
-apple_glx_diagnostic(const char *fmt, ...)
-{
- va_list vl;
-
- if (diagnostic) {
- fprintf(stderr, "DIAG: ");
-
- va_start(vl, fmt);
- vfprintf(stderr, fmt, vl);
- va_end(vl);
- }
-}
-
int
apple_get_dri_event_base(void)
{
@@ -125,10 +111,9 @@ apple_init_glx(Display * dpy)
if (initialized)
return false;
- if (getenv("LIBGL_DIAGNOSTIC")) {
- printf("initializing libGL in %s\n", __func__);
- diagnostic = true;
- }
+ apple_glx_log_init();
+
+ apple_glx_log(ASL_LEVEL_INFO, "Initializing libGL.");
apple_cgl_init();
(void) apple_glx_get_client_id();
diff --git a/src/glx/apple/apple_glx.h b/src/glx/apple/apple_glx.h
index ce8c4884d1a..0967f1812a0 100644
--- a/src/glx/apple/apple_glx.h
+++ b/src/glx/apple/apple_glx.h
@@ -38,7 +38,8 @@
#define XP_NO_X_HEADERS
#include <Xplugin.h>
-void apple_glx_diagnostic(const char *fmt, ...);
+#include "apple_glx_log.h"
+
xp_client_id apple_glx_get_client_id(void);
bool apple_init_glx(Display * dpy);
void apple_glx_swap_buffers(void *ptr);
diff --git a/src/glx/apple/apple_glx_log.c b/src/glx/apple/apple_glx_log.c
new file mode 100644
index 00000000000..9ebf666c9b4
--- /dev/null
+++ b/src/glx/apple/apple_glx_log.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2012 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#include <sys/cdefs.h>
+#include <asl.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include "apple_glx_log.h"
+
+static bool diagnostic = false;
+static aslclient aslc;
+
+void apple_glx_log_init(void) {
+ if (getenv("LIBGL_DIAGNOSTIC")) {
+ diagnostic = true;
+ }
+
+ aslc = asl_open(NULL, NULL, 0);
+}
+
+void _apple_glx_log(int level, const char *file, const char *function,
+ int line, const char *fmt, ...) {
+ va_list v;
+ va_start(v, fmt);
+ _apple_glx_vlog(level, file, function, line, fmt, v);
+ va_end(v);
+}
+
+static const char *
+_asl_level_string(int level)
+{
+ if (level == ASL_LEVEL_EMERG) return ASL_STRING_EMERG;
+ if (level == ASL_LEVEL_ALERT) return ASL_STRING_ALERT;
+ if (level == ASL_LEVEL_CRIT) return ASL_STRING_CRIT;
+ if (level == ASL_LEVEL_ERR) return ASL_STRING_ERR;
+ if (level == ASL_LEVEL_WARNING) return ASL_STRING_WARNING;
+ if (level == ASL_LEVEL_NOTICE) return ASL_STRING_NOTICE;
+ if (level == ASL_LEVEL_INFO) return ASL_STRING_INFO;
+ if (level == ASL_LEVEL_DEBUG) return ASL_STRING_DEBUG;
+ return "unknown";
+}
+
+void _apple_glx_vlog(int level, const char *file, const char *function,
+ int line, const char *fmt, va_list args) {
+ aslmsg msg;
+ uint64_t thread = 0;
+
+ if (pthread_is_threaded_np()) {
+ pthread_threadid_np(NULL, &thread);
+ }
+
+ if (diagnostic) {
+ va_list args2;
+ va_copy(args2, args);
+
+ fprintf(stderr, "%-9s %24s:%-4d %s(%"PRIu64"): ",
+ _asl_level_string(level), file, line, function, thread);
+ vfprintf(stderr, fmt, args2);
+ }
+
+ msg = asl_new(ASL_TYPE_MSG);
+ if (msg) {
+ if (file)
+ asl_set(msg, "File", file);
+ if (function)
+ asl_set(msg, "Function", function);
+ if (line) {
+ char *_line;
+ asprintf(&_line, "%d", line);
+ if (_line) {
+ asl_set(msg, "Line", _line);
+ free(_line);
+ }
+ }
+ if (pthread_is_threaded_np()) {
+ char *_thread;
+ asprintf(&_thread, "%"PRIu64, thread);
+ if (_thread) {
+ asl_set(msg, "Thread", _thread);
+ free(_thread);
+ }
+ }
+ }
+
+ asl_vlog(aslc, msg, level, fmt, args);
+ if (msg)
+ asl_free(msg);
+}
diff --git a/src/glx/apple/apple_glx_log.h b/src/glx/apple/apple_glx_log.h
new file mode 100644
index 00000000000..4b1c531d27f
--- /dev/null
+++ b/src/glx/apple/apple_glx_log.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#ifndef APPLE_GLX_LOG_H
+#define APPLE_GLX_LOG_H
+
+#include <sys/cdefs.h>
+#include <asl.h>
+
+void apple_glx_log_init(void);
+
+__printflike(5, 6)
+void _apple_glx_log(int level, const char *file, const char *function,
+ int line, const char *fmt, ...);
+#define apple_glx_log(l, f, args ...) \
+ _apple_glx_log(l, __FILE__, __FUNCTION__, __LINE__, f, ## args)
+
+
+__printflike(5, 0)
+void _apple_glx_vlog(int level, const char *file, const char *function,
+ int line, const char *fmt, va_list v);
+#define apple_glx_vlog(l, f, v) \
+ _apple_glx_vlog(l, __FILE__, __FUNCTION__, __LINE__, f, v)
+
+/* This is just here to help the transition.
+ * TODO: Replace calls to apple_glx_diagnostic
+ */
+#define apple_glx_diagnostic(f, args ...) \
+ apple_glx_log(ASL_LEVEL_DEBUG, f, ## args)
+
+#endif