1 /* 2 * Copyright (C) 2020 Alexandros Theodotou <alex at zrythm dot org> 3 * 4 * This file is part of ZToolkit 5 * 6 * ZToolkit is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Affero General Public License as 8 * published by the Free Software Foundation, either version 3 of the 9 * License, or (at your option) any later version. 10 * 11 * ZToolkit is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Affero General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Affero Public License 17 * along with ZToolkit. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 /** 21 * \file 22 * 23 * Logging utilities. 24 */ 25 26 #ifndef __Z_TOOLKIT_LOG_H__ 27 #define __Z_TOOLKIT_LOG_H__ 28 29 typedef enum ZtkLogLevel 30 { 31 ZTK_LOG_LEVEL_DEBUG, 32 ZTK_LOG_LEVEL_MESSAGE, 33 ZTK_LOG_LEVEL_WARNING, 34 ZTK_LOG_LEVEL_ERROR, 35 ZTK_LOG_LEVEL_OFF, 36 } ZtkLogLevel; 37 38 /** 39 * Sets the log level. 40 */ 41 void 42 ztk_log_set_level ( 43 ZtkLogLevel level); 44 45 /** 46 * Logs a message. 47 * 48 * @param func Function name. 49 * @param level Log level. 50 * @param format The format of the message to log. 51 */ 52 void 53 ztk_log ( 54 const char * func, 55 ZtkLogLevel level, 56 const char * format, 57 ...); 58 59 #define ztk_debug(...) \ 60 ztk_log (__func__, ZTK_LOG_LEVEL_DEBUG, \ 61 __VA_ARGS__) 62 63 #define ztk_message(...) \ 64 ztk_log (__func__, ZTK_LOG_LEVEL_MESSAGE, \ 65 __VA_ARGS__) 66 67 #define ztk_warning(...) \ 68 ztk_log (__func__, ZTK_LOG_LEVEL_WARNING, \ 69 __VA_ARGS__) 70 71 #define ztk_error(...) \ 72 ztk_log (__func__, ZTK_LOG_LEVEL_ERROR, \ 73 __VA_ARGS__) 74 75 #endif 76