Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | * not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #ifndef ETHOSU_LOG_H |
| 20 | #define ETHOSU_LOG_H |
| 21 | |
| 22 | /****************************************************************************** |
| 23 | * Includes |
| 24 | ******************************************************************************/ |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <string.h> |
| 28 | |
| 29 | /****************************************************************************** |
| 30 | * Defines |
| 31 | ******************************************************************************/ |
| 32 | |
| 33 | // Log severity levels |
| 34 | #define ETHOSU_LOG_ERR 0 |
| 35 | #define ETHOSU_LOG_WARN 1 |
| 36 | #define ETHOSU_LOG_INFO 2 |
| 37 | #define ETHOSU_LOG_DEBUG 3 |
| 38 | |
| 39 | // Define default log severity |
| 40 | #ifndef ETHOSU_LOG_SEVERITY |
| 41 | #define ETHOSU_LOG_SEVERITY ETHOSU_LOG_WARN |
| 42 | #endif |
| 43 | |
| 44 | // Log formatting |
| 45 | |
| 46 | #define LOG(f, ...) fprintf(stdout, f, ##__VA_ARGS__) |
| 47 | |
| 48 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_ERR |
Kristofer Jonsson | 089a347 | 2021-11-12 12:52:07 +0100 | [diff] [blame] | 49 | #define LOG_ERR(f, ...) fprintf(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 50 | #else |
| 51 | #define LOG_ERR(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 52 | #endif |
| 53 | |
| 54 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_WARN |
Kristofer Jonsson | 089a347 | 2021-11-12 12:52:07 +0100 | [diff] [blame] | 55 | #define LOG_WARN(f, ...) fprintf(stdout, "W: " f "\n", ##__VA_ARGS__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 56 | #else |
| 57 | #define LOG_WARN(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_INFO |
Kristofer Jonsson | 089a347 | 2021-11-12 12:52:07 +0100 | [diff] [blame] | 61 | #define LOG_INFO(f, ...) fprintf(stdout, "I: " f "\n", ##__VA_ARGS__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 62 | #else |
| 63 | #define LOG_INFO(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG |
Kristofer Jonsson | 089a347 | 2021-11-12 12:52:07 +0100 | [diff] [blame] | 67 | #define LOG_DEBUG(f, ...) fprintf(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 68 | #else |
| 69 | #define LOG_DEBUG(f, ...) |
Anton Moberg | 6eab40b | 2021-07-07 11:43:51 +0200 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | #endif |