Fix formatting issues
[platform/core/uifw/vulkan-wsi-tizen.git] / util / log.hpp
1 /*
2  * Copyright (c) 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
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
22  * SOFTWARE.
23  */
24
25 #pragma once
26 namespace util
27 {
28 #define WSI_DEFAULT_LOG_LEVEL 1
29
30 /**
31  * @brief Log a message to a certain log level
32  *
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.
39  *
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.
46  */
47
48 void wsi_log_message(int level, const char *file, int line, const char *format, ...)
49 #ifdef __GNUC__
50    __attribute__((format(printf, 4, 5)))
51 #endif
52    ;
53
54 #ifdef NDEBUG
55 static constexpr bool wsi_log_enable = false;
56 #else
57 static constexpr bool wsi_log_enable = true;
58 #endif
59
60 #define WSI_LOG(level, ...) \
61    do { if (::util::wsi_log_enable) ::util::wsi_log_message(level, __FILE__, __LINE__, __VA_ARGS__); } while (0)
62
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__)
66
67 } /* namespace util */