logger.h (3159B)
1 /** 2 * @file logger.h 3 * @author Adrian STEINER (steia19@bfh.ch) 4 * @brief Logger module to send debug and info messages 5 * @version 0.1 6 * @date 2024-06-07 7 * 8 * @copyright (C) 2025 Adrian STEINER 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program. If not, see <https: //www.gnu.org/licenses/>. 21 * 22 */ 23 24 #ifndef LOGGER_H 25 #define LOGGER_H 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /** 32 * @brief Configured log levels 33 * 34 */ 35 typedef enum { 36 LOG_OFF = 0, 37 LOG_ERROR, 38 LOG_WARN, 39 LOG_INFO, 40 LOG_DEBUG, 41 LOG_TRACE 42 } logger_logLevel; 43 44 #ifndef LOGGER_LEVEL 45 #define LOGGER_LEVEL (LOG_OFF) 46 #endif 47 48 #if (LOGGER_LEVEL > 4) 49 #define LOGGER_TRACE(...) logger_sendMsg(LOG_TRACE, __VA_ARGS__) 50 #else 51 #define LOGGER_TRACE(...) \ 52 do { \ 53 ; \ 54 } while (0) 55 56 #endif 57 58 #if (LOGGER_LEVEL > 3) 59 #define LOGGER_DEBUG(...) logger_sendMsg(LOG_DEBUG, __VA_ARGS__) 60 #else 61 #define LOGGER_DEBUG(...) \ 62 do { \ 63 ; \ 64 } while (0) 65 #endif 66 67 #if (LOGGER_LEVEL > 2) 68 #define LOGGER_INFO(...) logger_sendMsg(LOG_INFO, __VA_ARGS__) 69 #else 70 #define LOGGER_INFO(...) \ 71 do { \ 72 ; \ 73 } while (0) 74 #endif 75 76 #if (LOGGER_LEVEL > 1) 77 #define LOGGER_WARN(...) logger_sendMsg(LOG_WARN, __VA_ARGS__) 78 #else 79 #define LOGGER_WARN(...) \ 80 do { \ 81 ; \ 82 } while (0) 83 #endif 84 85 #if (LOGGER_LEVEL > 0) 86 #define LOGGER_ERROR(...) logger_sendMsg(LOG_ERROR, __VA_ARGS__) 87 #else 88 #define LOGGER_ERROR(...) \ 89 do { \ 90 ; \ 91 } while (0) 92 #endif 93 94 typedef void (*logger_output)(const char *); 95 96 void logger_init(logger_output outputCallback); 97 98 void logger_sendMsg(logger_logLevel logLevel, const char *format, ...); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 #endif /* UART_LOGGER_H */