ldap_log.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* $OpenLDAP$ */
  2. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 1998-2024 The OpenLDAP Foundation.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted only as authorized by the OpenLDAP
  9. * Public License.
  10. *
  11. * A copy of this license is available in file LICENSE in the
  12. * top-level directory of the distribution or, alternatively, at
  13. * <http://www.OpenLDAP.org/license.html>.
  14. */
  15. /* Portions Copyright (c) 1990 Regents of the University of Michigan.
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms are permitted
  19. * provided that this notice is preserved and that due credit is given
  20. * to the University of Michigan at Ann Arbor. The name of the University
  21. * may not be used to endorse or promote products derived from this
  22. * software without specific prior written permission. This software
  23. * is provided ``as is'' without express or implied warranty.
  24. */
  25. #ifndef LDAP_LOG_H
  26. #define LDAP_LOG_H
  27. #include <stdio.h>
  28. #include <ldap_cdefs.h>
  29. LDAP_BEGIN_DECL
  30. /*
  31. * debug reporting levels.
  32. *
  33. * They start with the syslog levels, and
  34. * go down in importance. The normal
  35. * debugging levels begin with LDAP_LEVEL_ENTRY
  36. *
  37. */
  38. /*
  39. * The "OLD_DEBUG" means that all logging occurs at LOG_DEBUG
  40. */
  41. #ifdef OLD_DEBUG
  42. /* original behavior: all logging occurs at the same severity level */
  43. #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
  44. #define LDAP_LEVEL_EMERG ldap_syslog_level
  45. #define LDAP_LEVEL_ALERT ldap_syslog_level
  46. #define LDAP_LEVEL_CRIT ldap_syslog_level
  47. #define LDAP_LEVEL_ERR ldap_syslog_level
  48. #define LDAP_LEVEL_WARNING ldap_syslog_level
  49. #define LDAP_LEVEL_NOTICE ldap_syslog_level
  50. #define LDAP_LEVEL_INFO ldap_syslog_level
  51. #define LDAP_LEVEL_DEBUG ldap_syslog_level
  52. #else /* !LDAP_DEBUG || !LDAP_SYSLOG */
  53. #define LDAP_LEVEL_EMERG (7)
  54. #define LDAP_LEVEL_ALERT (7)
  55. #define LDAP_LEVEL_CRIT (7)
  56. #define LDAP_LEVEL_ERR (7)
  57. #define LDAP_LEVEL_WARNING (7)
  58. #define LDAP_LEVEL_NOTICE (7)
  59. #define LDAP_LEVEL_INFO (7)
  60. #define LDAP_LEVEL_DEBUG (7)
  61. #endif /* !LDAP_DEBUG || !LDAP_SYSLOG */
  62. #else /* ! OLD_DEBUG */
  63. /* map syslog onto LDAP severity levels */
  64. #ifdef LOG_DEBUG
  65. #define LDAP_LEVEL_EMERG LOG_EMERG
  66. #define LDAP_LEVEL_ALERT LOG_ALERT
  67. #define LDAP_LEVEL_CRIT LOG_CRIT
  68. #define LDAP_LEVEL_ERR LOG_ERR
  69. #define LDAP_LEVEL_WARNING LOG_WARNING
  70. #define LDAP_LEVEL_NOTICE LOG_NOTICE
  71. #define LDAP_LEVEL_INFO LOG_INFO
  72. #define LDAP_LEVEL_DEBUG LOG_DEBUG
  73. #else /* ! LOG_DEBUG */
  74. #define LDAP_LEVEL_EMERG (0)
  75. #define LDAP_LEVEL_ALERT (1)
  76. #define LDAP_LEVEL_CRIT (2)
  77. #define LDAP_LEVEL_ERR (3)
  78. #define LDAP_LEVEL_WARNING (4)
  79. #define LDAP_LEVEL_NOTICE (5)
  80. #define LDAP_LEVEL_INFO (6)
  81. #define LDAP_LEVEL_DEBUG (7)
  82. #endif /* ! LOG_DEBUG */
  83. #endif /* ! OLD_DEBUG */
  84. #if 0
  85. /* in case we need to reuse the unused bits of severity */
  86. #define LDAP_LEVEL_MASK(s) ((s) & 0x7)
  87. #else
  88. #define LDAP_LEVEL_MASK(s) (s)
  89. #endif
  90. /* (yet) unused */
  91. #define LDAP_LEVEL_ENTRY (0x08) /* log function entry points */
  92. #define LDAP_LEVEL_ARGS (0x10) /* log function call parameters */
  93. #define LDAP_LEVEL_RESULTS (0x20) /* Log function results */
  94. #define LDAP_LEVEL_DETAIL1 (0x40) /* log level 1 function operational details */
  95. #define LDAP_LEVEL_DETAIL2 (0x80) /* Log level 2 function operational details */
  96. /* end of (yet) unused */
  97. /* original subsystem selection mechanism */
  98. #define LDAP_DEBUG_TRACE 0x0001
  99. #define LDAP_DEBUG_PACKETS 0x0002
  100. #define LDAP_DEBUG_ARGS 0x0004
  101. #define LDAP_DEBUG_CONNS 0x0008
  102. #define LDAP_DEBUG_BER 0x0010
  103. #define LDAP_DEBUG_FILTER 0x0020
  104. #define LDAP_DEBUG_CONFIG 0x0040
  105. #define LDAP_DEBUG_ACL 0x0080
  106. #define LDAP_DEBUG_STATS 0x0100
  107. #define LDAP_DEBUG_STATS2 0x0200
  108. #define LDAP_DEBUG_SHELL 0x0400
  109. #define LDAP_DEBUG_PARSE 0x0800
  110. #if 0 /* no longer used (nor supported) */
  111. #define LDAP_DEBUG_CACHE 0x1000
  112. #define LDAP_DEBUG_INDEX 0x2000
  113. #endif
  114. #define LDAP_DEBUG_SYNC 0x4000
  115. #define LDAP_DEBUG_NONE 0x8000
  116. #define LDAP_DEBUG_ANY (-1)
  117. /* debugging stuff */
  118. #ifdef LDAP_DEBUG
  119. /*
  120. * This is a bogus extern declaration for the compiler. No need to ensure
  121. * a 'proper' dllimport.
  122. */
  123. #ifndef ldap_debug
  124. extern int ldap_debug;
  125. #endif /* !ldap_debug */
  126. #ifdef LDAP_SYSLOG
  127. extern int ldap_syslog;
  128. extern int ldap_syslog_level;
  129. #ifdef HAVE_EBCDIC
  130. #define syslog eb_syslog
  131. extern void eb_syslog(int pri, const char *fmt, ...);
  132. #endif /* HAVE_EBCDIC */
  133. #endif /* LDAP_SYSLOG */
  134. #endif /* LDAP_DEBUG */
  135. /* we keep libldap working with preprocessors that can't do variadic macros */
  136. #ifndef LDAP_INT_DEBUG
  137. /* this doesn't below as part of ldap.h */
  138. #ifdef LDAP_DEBUG
  139. #ifdef LDAP_SYSLOG
  140. #define LogTest(level) ( ( ldap_debug | ldap_syslog ) & (level) )
  141. #define Log(level, severity, ...) \
  142. do { \
  143. if ( ldap_debug & (level) ) \
  144. lutil_debug( ldap_debug, (level), __VA_ARGS__ ); \
  145. if ( ldap_syslog & (level) ) \
  146. syslog( LDAP_LEVEL_MASK((severity)), __VA_ARGS__ ); \
  147. } while ( 0 )
  148. #else /* ! LDAP_SYSLOG */
  149. #define LogTest(level) ( ldap_debug & (level) )
  150. #define Log(level, severity, ...) \
  151. do { \
  152. if ( ldap_debug & (level) ) \
  153. lutil_debug( ldap_debug, (level), __VA_ARGS__ ); \
  154. } while ( 0 )
  155. #endif /* ! LDAP_SYSLOG */
  156. #else /* ! LDAP_DEBUG */
  157. /* TODO: in case LDAP_DEBUG is undefined, make sure logs with appropriate
  158. * severity gets thru anyway */
  159. #define LogTest(level) ( 0 )
  160. #define Log(level, severity, ...) ((void) 0)
  161. #endif /* ! LDAP_DEBUG */
  162. #define Debug(level, ...) \
  163. Log((level), ldap_syslog_level, __VA_ARGS__ )
  164. #endif /* ! LDAP_INT_DEBUG */
  165. /* Actually now in liblber/debug.c */
  166. LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
  167. LDAP_LUTIL_F(void) lutil_debug LDAP_P((
  168. int debug, int level,
  169. const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
  170. #ifdef LDAP_DEFINE_LDAP_DEBUG
  171. /* This struct matches the head of ldapoptions in <ldap-int.h> */
  172. struct ldapoptions_prefix {
  173. short ldo_valid;
  174. int ldo_debug;
  175. };
  176. #define ldap_debug \
  177. (*(int *) ((char *)&ldap_int_global_options \
  178. + offsetof(struct ldapoptions_prefix, ldo_debug)))
  179. struct ldapoptions;
  180. LDAP_V ( struct ldapoptions ) ldap_int_global_options;
  181. #endif /* LDAP_DEFINE_LDAP_DEBUG */
  182. LDAP_END_DECL
  183. #endif /* LDAP_LOG_H */