alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates |
| 3 | * <open-source-office@arm.com> SPDX-License-Identifier: Apache-2.0 |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 17 | #ifndef ML_EMBEDDED_CORE_LOG_H |
| 18 | #define ML_EMBEDDED_CORE_LOG_H |
| 19 | |
| 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 23 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 24 | #include <inttypes.h> |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 26 | |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 27 | #define LOG_LEVEL_TRACE 0 |
| 28 | #define LOG_LEVEL_DEBUG 1 |
| 29 | #define LOG_LEVEL_INFO 2 |
| 30 | #define LOG_LEVEL_WARN 3 |
| 31 | #define LOG_LEVEL_ERROR 4 |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 32 | |
| 33 | #ifndef LOG_LEVEL |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 34 | #define LOG_LEVEL LOG_LEVEL_INFO |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 35 | #endif /*LOG_LEVEL*/ |
| 36 | |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 37 | #if !defined(UNUSED) |
| 38 | #define UNUSED(x) ((void)(x)) |
| 39 | #endif /* #if !defined(UNUSED) */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 40 | |
| 41 | #if (LOG_LEVEL == LOG_LEVEL_TRACE) |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 42 | #define trace(...) \ |
| 43 | printf("TRACE - "); \ |
| 44 | printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 45 | #else |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 46 | #define trace(...) |
| 47 | #endif /* LOG_LEVEL == LOG_LEVEL_TRACE */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 48 | |
| 49 | #if (LOG_LEVEL <= LOG_LEVEL_DEBUG) |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 50 | #define debug(...) \ |
| 51 | printf("DEBUG - "); \ |
| 52 | printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 53 | #else |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 54 | #define debug(...) |
| 55 | #endif /* LOG_LEVEL > LOG_LEVEL_TRACE */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 56 | |
| 57 | #if (LOG_LEVEL <= LOG_LEVEL_INFO) |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 58 | #define info(...) \ |
| 59 | printf("INFO - "); \ |
| 60 | printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 61 | #else |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 62 | #define info(...) |
| 63 | #endif /* LOG_LEVEL > LOG_LEVEL_DEBUG */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 64 | |
| 65 | #if (LOG_LEVEL <= LOG_LEVEL_WARN) |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 66 | #define warn(...) \ |
| 67 | printf("WARN - "); \ |
| 68 | printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 69 | #else |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 70 | #define warn(...) |
| 71 | #endif /* LOG_LEVEL > LOG_LEVEL_INFO */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 72 | |
| 73 | #if (LOG_LEVEL <= LOG_LEVEL_ERROR) |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 74 | #define printf_err(...) \ |
| 75 | printf("ERROR - "); \ |
| 76 | printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 77 | #else |
Kshitij Sisodia | 657a54d | 2022-12-22 16:51:23 +0000 | [diff] [blame] | 78 | #define printf_err(...) |
| 79 | #endif /* LOG_LEVEL > LOG_LEVEL_INFO */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 80 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 81 | #ifdef __cplusplus |
| 82 | } |
| 83 | #endif |
| 84 | |
Kshitij Sisodia | 8c61c0a | 2022-05-17 11:16:22 +0100 | [diff] [blame] | 85 | #endif /* ML_EMBEDDED_CORE_LOG_H */ |