1 /* 2 * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LZ_HARDWARE_LOG_H 17 #define LZ_HARDWARE_LOG_H 18 19 #include "stdio.h" 20 21 enum { 22 LZ_HARDWARE_LOGE_LEVEL = 1, 23 LZ_HARDWARE_LOGW_LEVEL, 24 LZ_HARDWARE_LOGI_LEVEL, 25 LZ_HARDWARE_LOGD_LEVEL, 26 LZ_HARDWARE_LOGV_LEVEL, 27 }; 28 29 #define NONE "\e[0m" 30 #define RED "\e[0;31m" 31 #define GREEN "\e[0;32m" 32 #define BROWN "\e[0;33m" 33 #define BLUE "\e[0;34m" 34 35 #define LZ_HARDWARE_TRACE_LEVEL LZ_HARDWARE_LOGD_LEVEL 36 37 #define LZ_PRINTF(level, fmt, ...) do { \ 38 if (LZ_HARDWARE_TRACE_LEVEL >= level) printf(fmt, ##__VA_ARGS__); \ 39 } while (0) 40 41 #define LZ_HARDWARE_LOGV(tag, fmt, arg...) LZ_PRINTF(LZ_HARDWARE_LOGV_LEVEL, "[" tag ":V]" fmt "\n", ##arg) 42 #define LZ_HARDWARE_LOGD(tag, fmt, arg...) LZ_PRINTF(LZ_HARDWARE_LOGD_LEVEL, BLUE "[" tag ":D]" fmt "\n" NONE, ##arg) 43 #define LZ_HARDWARE_LOGI(tag, fmt, arg...) LZ_PRINTF(LZ_HARDWARE_LOGI_LEVEL, BROWN "[" tag ":I]" fmt "\n" NONE, ##arg) 44 #define LZ_HARDWARE_LOGW(tag, fmt, arg...) LZ_PRINTF(LZ_HARDWARE_LOGW_LEVEL, GREEN "[" tag ":W]" fmt "\n" NONE, ##arg) 45 #define LZ_HARDWARE_LOGE(tag, fmt, arg...) LZ_PRINTF(LZ_HARDWARE_LOGE_LEVEL, RED "[" tag ":E]" fmt "\n" NONE, ##arg) 46 47 #endif /* LZ_HARDWARE_LOG_H */ 48 49