dprint.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #ifndef dprint_h
  28. #define dprint_h
  29. #include <syslog.h>
  30. #define L_ALERT -3
  31. #define L_CRIT -2
  32. #define L_ERR -1
  33. #define L_WARN 1
  34. #define L_NOTICE 2
  35. #define L_INFO 3
  36. #define L_DBG 4
  37. /* vars:*/
  38. extern int debug;
  39. extern int log_stderr;
  40. #define DPRINT_LEV 1
  41. /* log facility (see syslog(3)) */
  42. #define L_FAC LOG_DAEMON
  43. /* priority at which we log */
  44. #define DPRINT_PRIO LOG_DEBUG
  45. void dprint (char* format, ...);
  46. #ifdef NO_DEBUG
  47. #ifdef __SUNPRO_C
  48. #define DPrint(...)
  49. #else
  50. #define DPrint(fmt, args...)
  51. #endif
  52. #else
  53. #ifdef __SUNPRO_C
  54. #define DPrint( ...) \
  55. do{ \
  56. if (debug>=DPRINT_LEV){ \
  57. if (log_stderr){ \
  58. dprint (__VA_ARGS__); \
  59. }else{ \
  60. syslog(DPRINT_LEV|L_FAC, __VA_ARGS__); \
  61. }\
  62. } \
  63. }while(0)
  64. #else
  65. #define DPrint(fmt,args...) \
  66. do{ \
  67. if (debug>=DPRINT_LEV){ \
  68. if (log_stderr){ \
  69. dprint (fmt, ## args); \
  70. }else{ \
  71. syslog(DPRINT_LEV|L_FAC, fmt, ## args); \
  72. }\
  73. } \
  74. }while(0)
  75. #endif
  76. #endif
  77. #ifndef NO_DEBUG
  78. #undef NO_LOG
  79. #endif
  80. #ifdef NO_LOG
  81. #ifdef __SUNPRO_C
  82. #define LOG(lev, ...)
  83. #else
  84. #define LOG(lev, fmt, args...)
  85. #endif
  86. #else
  87. #ifdef __SUNPRO_C
  88. #define LOG(lev, ...) \
  89. do { \
  90. if (debug>=(lev)){ \
  91. if (log_stderr) dprint (__VA_ARGS__); \
  92. else { \
  93. switch(lev){ \
  94. case L_CRIT: \
  95. syslog(LOG_CRIT | L_FAC, __VA_ARGS__); \
  96. break; \
  97. case L_ALERT: \
  98. syslog(LOG_ALERT | L_FAC, __VA_ARGS__); \
  99. break; \
  100. case L_ERR: \
  101. syslog(LOG_ERR | L_FAC, __VA_ARGS__); \
  102. break; \
  103. case L_WARN: \
  104. syslog(LOG_WARNING | L_FAC, __VA_ARGS__);\
  105. break; \
  106. case L_NOTICE: \
  107. syslog(LOG_NOTICE | L_FAC, __VA_ARGS__); \
  108. break; \
  109. case L_INFO: \
  110. syslog(LOG_INFO | L_FAC, __VA_ARGS__); \
  111. break; \
  112. case L_DBG: \
  113. syslog(LOG_DEBUG | L_FAC, __VA_ARGS__); \
  114. break; \
  115. } \
  116. } \
  117. } \
  118. }while(0)
  119. #else
  120. #define LOG(lev, fmt, args...) \
  121. do { \
  122. if (debug>=(lev)){ \
  123. if (log_stderr) dprint (fmt, ## args); \
  124. else { \
  125. switch(lev){ \
  126. case L_CRIT: \
  127. syslog(LOG_CRIT | L_FAC, fmt, ##args); \
  128. break; \
  129. case L_ALERT: \
  130. syslog(LOG_ALERT | L_FAC, fmt, ##args); \
  131. break; \
  132. case L_ERR: \
  133. syslog(LOG_ERR | L_FAC, fmt, ##args); \
  134. break; \
  135. case L_WARN: \
  136. syslog(LOG_WARNING | L_FAC, fmt, ##args); \
  137. break; \
  138. case L_NOTICE: \
  139. syslog(LOG_NOTICE | L_FAC, fmt, ##args); \
  140. break; \
  141. case L_INFO: \
  142. syslog(LOG_INFO | L_FAC, fmt, ##args); \
  143. break; \
  144. case L_DBG: \
  145. syslog(LOG_DEBUG | L_FAC, fmt, ##args); \
  146. break; \
  147. } \
  148. } \
  149. } \
  150. }while(0)
  151. #endif /*SUN_PRO_C*/
  152. #endif
  153. #ifdef NO_DEBUG
  154. #ifdef __SUNPRO_C
  155. #define DBG(...)
  156. #else
  157. #define DBG(fmt, args...)
  158. #endif
  159. #else
  160. #ifdef __SUNPRO_C
  161. #define DBG(...) LOG(L_DBG, __VA_ARGS__)
  162. #else
  163. #define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
  164. #endif
  165. #endif
  166. #endif /* ifndef dprint_h */