1 /* spmfilter - mail filtering framework 2 * Copyright (C) 2009-2012 Axel Steiner and SpaceNet AG 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 3 of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 /*! 19 * @file smf_trace.h 20 * @brief Logging functions 21 */ 22 23 #ifndef _SMF_TRACE_H 24 #define _SMF_TRACE_H 25 26 /*! 27 * @enum SMFTrace_T 28 * @brief Possible log levels 29 */ 30 typedef enum { 31 TRACE_EMERG = 1, 32 TRACE_ALERT = 2, 33 TRACE_CRIT = 4, 34 TRACE_ERR = 8, 35 TRACE_WARNING = 16, 36 TRACE_NOTICE = 32, 37 TRACE_INFO = 64, 38 TRACE_DEBUG = 128, 39 TRACE_LOOKUP = 256 // Logs at Debug Level 40 } SMFTrace_T; 41 42 /*! 43 * @enum SMFTraceDest_T 44 * @brief Trace destination 45 */ 46 typedef enum { 47 TRACE_DEST_SYSLOG, 48 TRACE_DEST_STDERR 49 } SMFTraceDest_T; 50 51 /*! 52 * @def TRACE(level, fmt...) trace(level, THIS_MODULE, __func__, __LINE__, fmt) 53 * @brief Convenience macro for logging 54 * @param level loglevel, see trace_t 55 * @param fmt format string for log message 56 * @param ... format string arguments 57 */ 58 #define TRACE(level, fmt...) trace(level, THIS_MODULE, __func__, __LINE__, NULL, fmt) 59 60 /*! 61 * @def STRACE(level, sid, fmt...) trace(level, THIS_MODULE, __func__, __LINE__, sid, fmt) 62 * @brief Log message with session id 63 */ 64 #define STRACE(level, sid, fmt...) trace(level, THIS_MODULE, __func__, __LINE__, sid, fmt) 65 66 #ifndef DOXYGEN_SHOULD_SKIP_THIS 67 void trace(SMFTrace_T level, const char * module, const char * function, int line, const char *sid, const char *formatstring, ...); 68 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 69 70 /*! 71 * @brief Configures the detail-level of a trace-entry. 72 * 73 * @param debug If set to 1, then the function and line-number are logged in in addition 74 */ 75 void configure_debug(int debug); 76 77 /*! 78 * @brief Configures the destination, where all the log-data are send to. 79 * 80 * @param dest The new logging-destination. The default is TRACE_DEST_SYSLOG. 81 */ 82 void configure_trace_destination(SMFTraceDest_T dest); 83 84 /*! 85 * @def TRDEBUG(fmt, ...) TRACE(TRACE_DEBUG, fmt, ##__VA_ARGS__) 86 * @brief Shortcut for logging with debug log level 87 */ 88 #define TRDEBUG(fmt, ...) TRACE(TRACE_DEBUG, fmt, ##__VA_ARGS__) 89 90 /*! 91 * @def TRINFO(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 92 * @brief Shortcut for logging with info log level 93 */ 94 #define TRINFO(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 95 96 /*! 97 * @def TRNOTICE(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 98 * @brief Shortcut for logging with notice log level 99 */ 100 #define TRNOTICE(fmt, ...) TRACE(TRACE_NOTICE, fmt, ##__VA_ARGS__) 101 102 /*! 103 * @def TRWARN(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 104 * @brief Shortcut for logging with warning log level 105 */ 106 #define TRWARN(fmt, ...) TRACE(TRACE_WARNING, fmt, ##__VA_ARGS__) 107 108 /*! 109 * @def TRERR(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 110 * @brief Shortcut for logging with error log level 111 */ 112 #define TRERR(fmt, ...) TRACE(TRACE_ERR, fmt, ##__VA_ARGS__) 113 114 /*! 115 * @def TRCRIT(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 116 * @brief Shortcut for logging with critical log level 117 */ 118 #define TRCRIT(fmt, ...) TRACE(TRACE_CRIT, fmt, ##__VA_ARGS__) 119 120 /*! 121 * @def TRALERT(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 122 * @brief Shortcut for logging with alert log level 123 */ 124 #define TRALERT(fmt, ...) TRACE(TRACE_ALERT, fmt, ##__VA_ARGS__) 125 126 /*! 127 * @def TREMERG(fmt, ...) TRACE(TRACE_INFO, fmt, ##__VA_ARGS__) 128 * @brief Shortcut for logging with ermegency log level 129 */ 130 #define TREMERG(fmt, ...) TRACE(TRACE_EMERG, fmt, ##__VA_ARGS__) 131 132 #endif /* _SMF_TRACE_H */ 133 134