su_debug.h 5.54 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

Pekka Pessi's avatar
Pekka Pessi committed
25 26
#ifndef SU_DEBUG_H
/** Defined when <sofia-sip/su_debug.h> has been included */
27
#define SU_DEBUG_H
Pekka Pessi's avatar
Pekka Pessi committed
28

Pekka Pessi's avatar
Pekka Pessi committed
29
/**@ingroup su_log
Pekka Pessi's avatar
Pekka Pessi committed
30
 * @file sofia-sip/su_debug.h
Pekka Pessi's avatar
Pekka Pessi committed
31 32 33
 * @brief SU debugging macros
 *
 * The logging levels and macros to use are defined as follows:
34
 *  - SU_DEBUG_0()  fatal errors, panic
35 36
 *  - SU_DEBUG_1()  critical errors, minimal progress at subsystem level
 *  - SU_DEBUG_2()  non-critical errors
Pekka Pessi's avatar
Pekka Pessi committed
37 38 39 40 41
 *  - SU_DEBUG_3()  warnings, progress messages
 *  - SU_DEBUG_5()  signaling protocol actions (incoming packets, etc.)
 *  - SU_DEBUG_7()  media protocol actions (incoming packets, etc.)
 *  - SU_DEBUG_9()  entering/exiting functions, very verbatim progress
 *
42 43 44
 * These macros are used to log with module-specific levels. The SU_LOG
 * macro is redefined with a pointer to a module-specific #su_log_t
 * structure, e.g., "iptsec_debug.h".
Pekka Pessi's avatar
Pekka Pessi committed
45 46
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
47
 *
Pekka Pessi's avatar
Pekka Pessi committed
48
 * @date Created: Tue Feb  8 10:06:33 2000 ppessi
49
 *
50
 * @sa @ref debug_logs, su_llog(), su_vllog(), #su_log_t,
Pekka Pessi's avatar
Pekka Pessi committed
51 52 53
 */

#ifndef SU_LOG_H
54
#include <sofia-sip/su_log.h>
Pekka Pessi's avatar
Pekka Pessi committed
55 56
#endif

57 58
SOFIA_BEGIN_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
59 60 61 62 63 64
#ifndef SU_DEBUG_MAX
/** The maximum debugging level. */
#define SU_DEBUG_MAX 9
#endif

#define SU_LOG_LEVEL \
65 66
((SU_LOG->log_init) == 0 ? 9 : \
((SU_LOG->log_init > 1) ? SU_LOG->log_level : su_log_default->log_level))
Pekka Pessi's avatar
Pekka Pessi committed
67 68 69 70 71

#if SU_DEBUG_MAX >= 0
#ifndef SU_LOG
#define SU_LOG       (su_log_default)
#else
72
SOFIAPUBVAR su_log_t SU_LOG[];
Pekka Pessi's avatar
Pekka Pessi committed
73 74 75
#endif

#define SU_DEBUG_DEF(level) \
Pekka Pessi's avatar
Pekka Pessi committed
76
  su_inline void su_debug_##level(char const *fmt, ...) \
Pekka Pessi's avatar
Pekka Pessi committed
77
    __attribute__ ((__format__ (printf, 1, 2))); \
Pekka Pessi's avatar
Pekka Pessi committed
78
  su_inline void su_debug_##level(char const *fmt, ...) \
Pekka Pessi's avatar
Pekka Pessi committed
79 80 81
    { va_list ap; va_start(ap, fmt); su_vllog(SU_LOG, level, fmt, ap); va_end(ap); }

SU_DEBUG_DEF(0)
82 83
/** Log messages at level 0.
 *
84
 * Fatal errors and panic messages should be logged at level 0.
85 86 87
 *
 * @sa su_llog(), su_vllog(), #su_log_t, @ref debug_logs
 */
88
#define SU_DEBUG_0(x) (su_debug_0 x)
Pekka Pessi's avatar
Pekka Pessi committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102

/** Log C library errors. */
#define SU_LERROR(s) (su_llog(SU_LOG, 1, "%s: %s\n", (s), strerror(errno)))
/** Log socket errors. */
#define SU_LSERROR(s) \
  (su_llog(SU_LOG, 1, "%s: %s\n", (s), su_strerror(su_errno())))
#else
#define SU_DEBUG_0(x) ((void)0)
#define SU_LERROR(s)  ((void)0)
#define SU_LSERROR(s) ((void)0)
#endif

#if SU_DEBUG_MAX >= 1
SU_DEBUG_DEF(1)
103 104 105 106 107 108 109
/**Log messages at level 1.
 *
 * Critical errors and minimal progress at subsystem level should be logged
 * at level 1.
 *
 * @sa su_llog(), su_vllog(), #su_log_t, @ref debug_logs
 */
Pekka Pessi's avatar
Pekka Pessi committed
110 111 112 113 114 115 116
#define SU_DEBUG_1(x) (SU_LOG_LEVEL >= 1 ? (su_debug_1 x) : (void)0)
#else
#define SU_DEBUG_1(x) (void)1
#endif

#if SU_DEBUG_MAX >= 2
SU_DEBUG_DEF(2)
117
/**Log messages at level 2.
118 119 120 121 122
 *
 * Non-critical errors should be logged at level 2.
 *
 * @sa su_llog(), su_vllog(), #su_log_t, @ref debug_logs
 */
Pekka Pessi's avatar
Pekka Pessi committed
123 124 125 126 127 128 129
#define SU_DEBUG_2(x) (SU_LOG_LEVEL >= 2 ? (su_debug_2 x) : (void)0)
#else
#define SU_DEBUG_2(x) (void)2
#endif

#if SU_DEBUG_MAX >= 3
SU_DEBUG_DEF(3)
130 131 132 133 134 135
/** Log messages at level 3.
 *
 * Warnings and progress messages should be logged at level 3.
 *
 * @sa su_llog(), su_vllog(), #su_log_t, @ref debug_logs
 */
Pekka Pessi's avatar
Pekka Pessi committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
#define SU_DEBUG_3(x) (SU_LOG_LEVEL >= 3 ? (su_debug_3 x) : (void)0)
#else
#define SU_DEBUG_3(x) (void)3
#endif

#if SU_DEBUG_MAX >= 4
SU_DEBUG_DEF(4)
/** Log messages at level 4. */
#define SU_DEBUG_4(x) (SU_LOG_LEVEL >= 4 ? (su_debug_4 x) : (void)0)
#else
#define SU_DEBUG_4(x) (void)4
#endif

#if SU_DEBUG_MAX >= 5
SU_DEBUG_DEF(5)
151 152 153 154 155 156 157
/** Log messages at level 5.
 *
 * Signaling protocol actions (incoming packets, etc.) should be logged
 * at level 5.
 *
 * @sa su_llog(), su_vllog(), #su_log_t, @ref debug_logs
 */
Pekka Pessi's avatar
Pekka Pessi committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
#define SU_DEBUG_5(x) (SU_LOG_LEVEL >= 5 ? (su_debug_5 x) : (void)0)
#else
#define SU_DEBUG_5(x) (void)5
#endif

#if SU_DEBUG_MAX >= 6
SU_DEBUG_DEF(6)
/** Log messages at level 6. */
#define SU_DEBUG_6(x) (SU_LOG_LEVEL >= 6 ? (su_debug_6 x) : (void)0)
#else
#define SU_DEBUG_6(x) (void)6
#endif

#if SU_DEBUG_MAX >= 7
SU_DEBUG_DEF(7)
173 174
/** Log messages at level 7.
 *
175
 * Media protocol actions (incoming packets, etc) should be logged at level 7.
176 177 178
 *
 * @sa su_llog(), su_vllog(), #su_log_t, @ref debug_logs
 */
Pekka Pessi's avatar
Pekka Pessi committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
#define SU_DEBUG_7(x) (SU_LOG_LEVEL >= 7 ? (su_debug_7 x) : (void)0)
#else
#define SU_DEBUG_7(x) (void)7
#endif

#if SU_DEBUG_MAX >= 8
SU_DEBUG_DEF(8)
/** Log messages at level 8. */
#define SU_DEBUG_8(x) (SU_LOG_LEVEL >= 8 ? (su_debug_8 x) : (void)0)
#else
#define SU_DEBUG_8(x) (void)8
#endif

#if SU_DEBUG_MAX >= 9
SU_DEBUG_DEF(9)
194 195 196 197 198 199 200
/** Log messages at level 9.
 *
 * Entering/exiting functions, very verbatim progress should be logged at
 * level 9.
 *
 * @sa su_llog(), su_vllog(), #su_log_t, @ref debug_logs
 */
Pekka Pessi's avatar
Pekka Pessi committed
201 202 203 204 205
#define SU_DEBUG_9(x) (SU_LOG_LEVEL >= 9 ? (su_debug_9 x) : (void)0)
#else
#define SU_DEBUG_9(x) (void)9
#endif

206 207
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
208
#endif /* SU_DEBUG_H */