1 /* 2 * Copyright (c) 2017 Linaro Limited 3 * Copyright (c) 2019 Arm Limited. 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 */ 17 18 #ifndef __MCUBOOT_LOGGING_H__ 19 #define __MCUBOOT_LOGGING_H__ 20 21 #include "bootutil/ignore.h" 22 #include <stdio.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define MCUBOOT_LOG_LEVEL_OFF 0 29 #define MCUBOOT_LOG_LEVEL_ERROR 1 30 #define MCUBOOT_LOG_LEVEL_WARNING 2 31 #define MCUBOOT_LOG_LEVEL_INFO 3 32 #define MCUBOOT_LOG_LEVEL_DEBUG 4 33 34 /* 35 * The compiled log level determines the maximum level that can be 36 * printed. Messages at or below this level can be printed. 37 */ 38 #ifndef MCUBOOT_LOG_LEVEL 39 #define MCUBOOT_LOG_LEVEL MCUBOOT_LOG_LEVEL_INFO 40 #endif 41 42 #define MCUBOOT_LOG_MODULE_DECLARE(domain) /* Ignore */ 43 #define MCUBOOT_LOG_MODULE_REGISTER(domain) /* Ignore */ 44 45 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_ERROR 46 #define MCUBOOT_LOG_ERR(_fmt, ...) \ 47 printf("[ERR] " _fmt "\r\n", ##__VA_ARGS__) 48 #else 49 #define MCUBOOT_LOG_ERR(...) IGNORE(__VA_ARGS__) 50 #endif 51 52 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_WARNING 53 #define MCUBOOT_LOG_WRN(_fmt, ...) \ 54 printf("[WRN] " _fmt "\r\n", ##__VA_ARGS__) 55 #else 56 #define MCUBOOT_LOG_WRN(...) IGNORE(__VA_ARGS__) 57 #endif 58 59 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_INFO 60 #define MCUBOOT_LOG_INF(_fmt, ...) \ 61 printf("[INF] " _fmt "\r\n", ##__VA_ARGS__) 62 #else 63 #define MCUBOOT_LOG_INF(...) IGNORE(__VA_ARGS__) 64 #endif 65 66 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_DEBUG 67 #define MCUBOOT_LOG_DBG(_fmt, ...) \ 68 printf("[DBG] " _fmt "\r\n", ##__VA_ARGS__) 69 #else 70 #define MCUBOOT_LOG_DBG(...) IGNORE(__VA_ARGS__) 71 #endif 72 73 #ifdef __cplusplus 74 } 75 #endif 76 77 #endif /* __MCUBOOT_LOGGING_H__ */ 78