2 * Copyright (c) 2021 Arm Limited.
4 * SPDX-License-Identifier: MIT
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, 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 DEALINGS IN THE
28 #define WSI_DEFAULT_LOG_LEVEL 1
31 * @brief Log a message to a certain log level
33 * @details For the log level, we use a bigger integer to represent an increased
34 * level of verbosity. If this is not specified, the log level is default to 1.
35 * We use a "staircase" approach with respect to printing logs. We print all log
36 * messages equal or below the log level set, e.g. if VULKAN_WSI_DEBUG_LEVEL
37 * is set to 2, messages with log level 1 and 2 are printed. Please note that
38 * the newline character '\n' is automatically appended.
40 * @param[in] level The log level of this message, you can set an arbitary
41 * integer however please refer to the included macros for
42 * the sensible defaults.
43 * @param[in] file The source file name (``__FILE__``)
44 * @param[in] line The source file line number (``__LINE__``)
45 * @param[in] format A C-style formatting string.
48 void wsi_log_message(int level, const char *file, int line, const char *format, ...)
50 __attribute__((format(printf, 4, 5)))
55 static constexpr bool wsi_log_enable = false;
57 static constexpr bool wsi_log_enable = true;
60 #define WSI_LOG(level, ...) \
61 do { if (::util::wsi_log_enable) ::util::wsi_log_message(level, __FILE__, __LINE__, __VA_ARGS__); } while (0)
63 #define WSI_LOG_ERROR(...) WSI_LOG(1, __VA_ARGS__)
64 #define WSI_LOG_WARNING(...) WSI_LOG(2, __VA_ARGS__)
65 #define WSI_LOG_INFO(...) WSI_LOG(3, __VA_ARGS__)
67 } /* namespace util */