su_debug.h 4.72 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
 * * This library is free software; you can redistribute it and/or
 * 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
 *
 */

#ifndef SU_DEBUG_H /** Defined when su_debug.h has been included */
#define SU_DEBUG_H \
"$Id: su_debug.h,v 1.1.1.1 2005/07/20 20:35:57 kaiv Exp $"
/**@ingroup su_log
 * @file su_debug.h
 * @brief SU debugging macros
 *
 * The logging levels and macros to use are defined as follows:
 *  - su_log()      fatal errors, panic 
 *  - SU_DEBUG_0()  critical errors, minimal progress at subsystem level
 *  - SU_DEBUG_1()  non-critical errors
 *  - 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
 *
 * Module-specific logging requires redefining SU_LOG macro with a pointer
 * to a su_log_t variable.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * 
 * @date Created: Tue Feb  8 10:06:33 2000 ppessi
 * $Date: 2005/07/20 20:35:57 $
 */

#ifndef SU_LOG_H
#include <su_log.h>
#endif

#ifndef SU_DEBUG_MAX
/** The maximum debugging level. */
#define SU_DEBUG_MAX 9
#endif

#define SU_LOG_LEVEL \
((SU_LOG != NULL && SU_LOG->log_init) == 0 ? 9 : \
((SU_LOG != NULL && SU_LOG->log_init > 1) ? \
  SU_LOG->log_level : su_log_default->log_level))

#ifndef SU_CONFIG_H
#include <su_config.h>
#endif

#if SU_DEBUG_MAX >= 0
#ifndef SU_LOG
#define SU_LOG       (su_log_default)
#else
extern su_log_t SU_LOG[];
#endif

#define SU_DEBUG_DEF(level) \
  static SU_INLINE void su_debug_##level(char const *fmt, ...) \
    __attribute__ ((__format__ (printf, 1, 2))); \
  void su_debug_##level(char const *fmt, ...) \
    { va_list ap; va_start(ap, fmt); su_vllog(SU_LOG, level, fmt, ap); va_end(ap); }

SU_DEBUG_DEF(0)
/** Log critical errors, minimal progress at subsystem level. */
#define SU_DEBUG_0(x) (SU_LOG_LEVEL >= 0 ? (su_debug_0 x) : (void)0)

/** 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)
/** Log non-critical errors. */
#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)
/** Log messages at level 2. */
#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)
/** Log warnings, progress messages. */
#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)
/** Log signaling protocol actions (incoming packets, etc.). */
#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)
/** Log media protocol actions (incoming packets, etc.). */
#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)
/** Log entering/exiting functions, very verbatim progress. */
#define SU_DEBUG_9(x) (SU_LOG_LEVEL >= 9 ? (su_debug_9 x) : (void)0)
#else
#define SU_DEBUG_9(x) (void)9
#endif

#endif /* SU_DEBUG_H */