Harrison Mutai | 88d6ec8 | 2025-08-12 14:32:58 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef DEBUG_H |
| 8 | #define DEBUG_H |
| 9 | |
| 10 | #include DEBUG_BACKEND_HEADER |
| 11 | |
| 12 | /* |
| 13 | * The log output macros print output to the console. These macros produce |
| 14 | * compiled log output only if the EVLOG_LOG_LEVEL defined in the makefile (or the |
| 15 | * make command line) is greater or equal than the level required for that |
| 16 | * type of log output. |
| 17 | * |
| 18 | * The format expected is the same as for printf(). For example: |
| 19 | * INFO("Info %s.\n", "message") -> INFO: Info message. |
| 20 | * WARN("Warning %s.\n", "message") -> WARNING: Warning message. |
| 21 | */ |
| 22 | |
| 23 | #define EVLOG_LEVEL_NONE 0 |
| 24 | #define EVLOG_LEVEL_ERROR 10 |
| 25 | #define EVLOG_LEVEL_NOTICE 20 |
| 26 | #define EVLOG_LEVEL_WARNING 30 |
| 27 | #define EVLOG_LEVEL_INFO 40 |
| 28 | #define EVLOG_LEVEL_VERBOSE 50 |
| 29 | |
| 30 | /* |
| 31 | * If the log output is too low then this macro is used in place of evlog_log() |
| 32 | * below. The intent is to get the compiler to evaluate the function call for |
| 33 | * type checking and format specifier correctness but let it optimize it out. |
| 34 | */ |
| 35 | #define no_evlog_log(fmt, ...) \ |
| 36 | do { \ |
| 37 | if (false) { \ |
| 38 | evlog_log(fmt, ##__VA_ARGS__); \ |
| 39 | } \ |
| 40 | } while (false) |
| 41 | |
| 42 | #if EVLOG_LOG_LEVEL >= EVLOG_LEVEL_ERROR |
| 43 | #define ERROR(...) evlog_log(EVLOG_MARKER_ERROR __VA_ARGS__) |
| 44 | #else |
| 45 | #define ERROR(...) no_evlog_log(EVLOG_MARKER_ERROR __VA_ARGS__) |
| 46 | #endif |
| 47 | |
| 48 | #if EVLOG_LOG_LEVEL >= EVLOG_LEVEL_NOTICE |
| 49 | #define NOTICE(...) evlog_log(EVLOG_MARKER_NOTICE __VA_ARGS__) |
| 50 | #else |
| 51 | #define NOTICE(...) no_evlog_log(EVLOG_MARKER_NOTICE __VA_ARGS__) |
| 52 | #endif |
| 53 | |
| 54 | #if EVLOG_LOG_LEVEL >= EVLOG_LEVEL_WARNING |
| 55 | #define WARN(...) evlog_log(EVLOG_MARKER_WARNING __VA_ARGS__) |
| 56 | #else |
| 57 | #define WARN(...) no_evlog_log(EVLOG_MARKER_WARNING __VA_ARGS__) |
| 58 | #endif |
| 59 | |
| 60 | #if EVLOG_LOG_LEVEL >= EVLOG_LEVEL_INFO |
| 61 | #define INFO(...) evlog_log(EVLOG_MARKER_INFO __VA_ARGS__) |
| 62 | #else |
| 63 | #define INFO(...) no_evlog_log(EVLOG_MARKER_INFO __VA_ARGS__) |
| 64 | #endif |
| 65 | |
| 66 | #if EVLOG_LOG_LEVEL >= EVLOG_LEVEL_VERBOSE |
| 67 | #define VERBOSE(...) evlog_log(EVLOG_MARKER_VERBOSE __VA_ARGS__) |
| 68 | #else |
| 69 | #define VERBOSE(...) no_evlog_log(EVLOG_MARKER_VERBOSE __VA_ARGS__) |
| 70 | #endif |
| 71 | |
| 72 | #endif /* DEBUG_H */ |