alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | * SPDX-License-Identifier: Apache-2.0 |
| 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 | |
| 24 | #include <stdio.h> |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 25 | #include <inttypes.h> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 26 | |
| 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 |
| 32 | |
| 33 | #ifndef LOG_LEVEL |
| 34 | #define LOG_LEVEL LOG_LEVEL_INFO |
| 35 | #endif /*LOG_LEVEL*/ |
| 36 | |
| 37 | #define UNUSED(x) ((void)(x)) |
| 38 | |
| 39 | #if (LOG_LEVEL == LOG_LEVEL_TRACE) |
Isabella Gottardi | 8df12f3 | 2021-04-07 17:15:31 +0100 | [diff] [blame] | 40 | #define trace(...) printf("TRACE - "); printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 41 | #else |
| 42 | #define trace(...) |
| 43 | #endif /* LOG_LEVEL == LOG_LEVEL_TRACE */ |
| 44 | |
| 45 | #if (LOG_LEVEL <= LOG_LEVEL_DEBUG) |
Isabella Gottardi | 8df12f3 | 2021-04-07 17:15:31 +0100 | [diff] [blame] | 46 | #define debug(...) printf("DEBUG - "); printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 47 | #else |
| 48 | #define debug(...) |
| 49 | #endif /* LOG_LEVEL > LOG_LEVEL_TRACE */ |
| 50 | |
| 51 | #if (LOG_LEVEL <= LOG_LEVEL_INFO) |
Isabella Gottardi | 8df12f3 | 2021-04-07 17:15:31 +0100 | [diff] [blame] | 52 | #define info(...) printf("INFO - "); printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 53 | #else |
| 54 | #define info(...) |
| 55 | #endif /* LOG_LEVEL > LOG_LEVEL_DEBUG */ |
| 56 | |
| 57 | #if (LOG_LEVEL <= LOG_LEVEL_WARN) |
Isabella Gottardi | 8df12f3 | 2021-04-07 17:15:31 +0100 | [diff] [blame] | 58 | #define warn(...) printf("WARN - "); printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 59 | #else |
| 60 | #define warn(...) |
| 61 | #endif /* LOG_LEVEL > LOG_LEVEL_INFO */ |
| 62 | |
| 63 | #if (LOG_LEVEL <= LOG_LEVEL_ERROR) |
Isabella Gottardi | 8df12f3 | 2021-04-07 17:15:31 +0100 | [diff] [blame] | 64 | #define printf_err(...) printf("ERROR - "); printf(__VA_ARGS__) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 65 | #else |
| 66 | #define printf_err(...) |
| 67 | #endif /* LOG_LEVEL > LOG_LEVEL_INFO */ |
| 68 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 69 | #ifdef __cplusplus |
| 70 | } |
| 71 | #endif |
| 72 | |
Kshitij Sisodia | 8c61c0a | 2022-05-17 11:16:22 +0100 | [diff] [blame^] | 73 | #endif /* ML_EMBEDDED_CORE_LOG_H */ |