2 * Copyright 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include "piglit-log.h"
29 #include "piglit-util.h"
31 struct piglit_log_opt_list
{
37 * Array of logging options, one entry for each value of enum piglit_log_opt.
39 static struct piglit_log_opt_list opts
[PIGLIT_LOG_OPT_MAX
+ 1];
42 get_env_overrides(void)
44 static bool once
= true;
45 const char *env
= NULL
;
52 env
= getenv("PIGLIT_LOG_PRINT_TID");
53 if (env
&& !streq(env
, "")) {
54 opts
[PIGLIT_LOG_PRINT_TID
].is_env_set
= true;
55 opts
[PIGLIT_LOG_PRINT_TID
].val
= atoi(env
);
59 /** Is option out of bounds? */
61 is_opt_oob(enum piglit_log_opt opt
)
63 return opt
> PIGLIT_LOG_OPT_MAX
;
67 piglit_log_get_opt(enum piglit_log_opt opt
)
71 if (is_opt_oob(opt
)) {
79 piglit_log_set_opt(enum piglit_log_opt opt
, intptr_t value
) {
82 if (is_opt_oob(opt
) || opts
[opt
].is_env_set
) {
86 opts
[opt
].val
= value
;
90 piglit_log_tagv(const char *tag
, const char *fmt
, va_list ap
)
93 if (piglit_log_get_opt(PIGLIT_LOG_PRINT_TID
)) {
94 printf("(%"PRIu64
")", piglit_gettid());
96 printf(": %s: ", tag
);
102 piglit_loge(const char *fmt
, ...)
106 piglit_log_tagv("error", fmt
, ap
);
111 piglit_logi(const char *fmt
, ...)
115 piglit_log_tagv("info", fmt
, ap
);
120 piglit_logd(const char *fmt
, ...)
122 static bool once
= true;
123 static bool debug
= false;
130 env
= getenv("PIGLIT_DEBUG");
135 || streq(env
, "false")) {
137 } else if (streq(env
, "1")
138 || streq(env
, "true")) {
141 piglit_loge("PIGLIT_DEBUG has invalid value: "
152 piglit_log_tagv("debug", fmt
, ap
);