2 * Copyright (c) 2012 Apple Inc.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
19 * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 * Except as contained in this notice, the name(s) of the above
25 * copyright holders shall not be used in advertising or otherwise to
26 * promote the sale, use or other dealings in this Software without
27 * prior written authorization.
30 #include <sys/cdefs.h>
38 #include "apple_glx_log.h"
40 static bool diagnostic
= false;
41 static aslclient aslc
;
43 void apple_glx_log_init(void) {
44 if (getenv("LIBGL_DIAGNOSTIC")) {
48 aslc
= asl_open(NULL
, NULL
, 0);
51 void _apple_glx_log(int level
, const char *file
, const char *function
,
52 int line
, const char *fmt
, ...) {
55 _apple_glx_vlog(level
, file
, function
, line
, fmt
, v
);
60 _asl_level_string(int level
)
62 if (level
== ASL_LEVEL_EMERG
) return ASL_STRING_EMERG
;
63 if (level
== ASL_LEVEL_ALERT
) return ASL_STRING_ALERT
;
64 if (level
== ASL_LEVEL_CRIT
) return ASL_STRING_CRIT
;
65 if (level
== ASL_LEVEL_ERR
) return ASL_STRING_ERR
;
66 if (level
== ASL_LEVEL_WARNING
) return ASL_STRING_WARNING
;
67 if (level
== ASL_LEVEL_NOTICE
) return ASL_STRING_NOTICE
;
68 if (level
== ASL_LEVEL_INFO
) return ASL_STRING_INFO
;
69 if (level
== ASL_LEVEL_DEBUG
) return ASL_STRING_DEBUG
;
73 void _apple_glx_vlog(int level
, const char *file
, const char *function
,
74 int line
, const char *fmt
, va_list args
) {
78 if (pthread_is_threaded_np()) {
79 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
80 thread
= (uint64_t)(uintptr_t)pthread_self();
81 #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060
82 if (&pthread_threadid_np
) {
83 pthread_threadid_np(NULL
, &thread
);
85 thread
= (uint64_t)(uintptr_t)pthread_self();
88 pthread_threadid_np(NULL
, &thread
);
96 fprintf(stderr
, "%-9s %24s:%-4d %s(%"PRIu64
"): ",
97 _asl_level_string(level
), file
, line
, function
, thread
);
98 vfprintf(stderr
, fmt
, args2
);
101 msg
= asl_new(ASL_TYPE_MSG
);
104 asl_set(msg
, "File", file
);
106 asl_set(msg
, "Function", function
);
109 asprintf(&_line
, "%d", line
);
111 asl_set(msg
, "Line", _line
);
115 if (pthread_is_threaded_np()) {
117 asprintf(&_thread
, "%"PRIu64
, thread
);
119 asl_set(msg
, "Thread", _thread
);
125 asl_vlog(aslc
, msg
, level
, fmt
, args
);