Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 1 | /* |
Ledion Daja | ecdce6c | 2023-01-16 15:39:29 +0100 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | * not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * 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, WITHOUT |
| 13 | * 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 | */ |
| 17 | |
| 18 | #ifndef ETHOSU_LOG_H |
| 19 | #define ETHOSU_LOG_H |
| 20 | |
| 21 | /****************************************************************************** |
| 22 | * Includes |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | /****************************************************************************** |
| 29 | * Defines |
| 30 | ******************************************************************************/ |
| 31 | |
| 32 | // Log severity levels |
| 33 | #define ETHOSU_LOG_ERR 0 |
| 34 | #define ETHOSU_LOG_WARN 1 |
| 35 | #define ETHOSU_LOG_INFO 2 |
| 36 | #define ETHOSU_LOG_DEBUG 3 |
| 37 | |
| 38 | // Define default log severity |
| 39 | #ifndef ETHOSU_LOG_SEVERITY |
| 40 | #define ETHOSU_LOG_SEVERITY ETHOSU_LOG_WARN |
| 41 | #endif |
| 42 | |
Jonny Svärd | 0189cd2 | 2023-10-11 13:33:44 +0000 | [diff] [blame] | 43 | // Logs enabled by default |
| 44 | #ifndef ETHOSU_LOG_ENABLE |
| 45 | #define ETHOSU_LOG_ENABLE 1 |
| 46 | #endif |
| 47 | |
| 48 | #if ETHOSU_LOG_ENABLE |
| 49 | #define LOG_COMMON(s, f, ...) (void)fprintf(s, f, ##__VA_ARGS__) |
| 50 | #else |
| 51 | #define LOG_COMMON(s, f, ...) |
| 52 | #endif |
| 53 | |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 54 | // Log formatting |
Jonny Svärd | 0189cd2 | 2023-10-11 13:33:44 +0000 | [diff] [blame] | 55 | #define LOG(f, ...) LOG_COMMON(stdout, f, ##__VA__ARGS__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 56 | |
| 57 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR |
Ledion Daja | ecdce6c | 2023-01-16 15:39:29 +0100 | [diff] [blame] | 58 | #define LOG_ERR(f, ...) \ |
Jonny Svärd | 0189cd2 | 2023-10-11 13:33:44 +0000 | [diff] [blame] | 59 | LOG_COMMON(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 60 | #else |
| 61 | #define LOG_ERR(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 62 | #endif |
| 63 | |
| 64 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_WARN |
Jonny Svärd | 0189cd2 | 2023-10-11 13:33:44 +0000 | [diff] [blame] | 65 | #define LOG_WARN(f, ...) LOG_COMMON(stdout, "W: " f "\n", ##__VA_ARGS__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 66 | #else |
| 67 | #define LOG_WARN(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 68 | #endif |
| 69 | |
| 70 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_INFO |
Jonny Svärd | 0189cd2 | 2023-10-11 13:33:44 +0000 | [diff] [blame] | 71 | #define LOG_INFO(f, ...) LOG_COMMON(stdout, "I: " f "\n", ##__VA_ARGS__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 72 | #else |
| 73 | #define LOG_INFO(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 74 | #endif |
| 75 | |
| 76 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG |
Jonny Svärd | 0189cd2 | 2023-10-11 13:33:44 +0000 | [diff] [blame] | 77 | #define LOG_DEBUG(f, ...) LOG_COMMON(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 78 | #else |
| 79 | #define LOG_DEBUG(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 80 | #endif |
| 81 | |
Jonny Svärd | 0189cd2 | 2023-10-11 13:33:44 +0000 | [diff] [blame] | 82 | #endif |