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 49 #define LOG_ERR(f, ...) fprintf(stderr, "E: " f " (%s:%d)\n", ##__VA_ARGS__, strrchr("/" __FILE__, '/') + 1, __LINE__) 50 #else 51 #define LOG_ERR(f, ...) 52 #endif 53 54 #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_WARN 55 #define LOG_WARN(f, ...) fprintf(stdout, "W: " f "\n", ##__VA_ARGS__) 56 #else 57 #define LOG_WARN(f, ...) 58 #endif 59 60 #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_INFO 61 #define LOG_INFO(f, ...) fprintf(stdout, "I: " f "\n", ##__VA_ARGS__) 62 #else 63 #define LOG_INFO(f, ...) 64 #endif 65 66 #if ETHOSU_LOG_SEVERITY >= ETHOSU_LOG_DEBUG 67 #define LOG_DEBUG(f, ...) fprintf(stdout, "D: %s(): " f "\n", __FUNCTION__, ##__VA_ARGS__) 68 #else 69 #define LOG_DEBUG(f, ...) 70 #endif 71 72 #endif