2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2012 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
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.
30 #include <ldap_cdefs.h>
35 * debug reporting levels.
37 * They start with the syslog levels, and
38 * go down in importance. The normal
39 * debugging levels begin with LDAP_LEVEL_ENTRY
44 * The "OLD_DEBUG" means that all logging occurs at LOG_DEBUG
48 /* original behavior: all logging occurs at the same severity level */
49 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
50 #define LDAP_LEVEL_EMERG ldap_syslog_level
51 #define LDAP_LEVEL_ALERT ldap_syslog_level
52 #define LDAP_LEVEL_CRIT ldap_syslog_level
53 #define LDAP_LEVEL_ERR ldap_syslog_level
54 #define LDAP_LEVEL_WARNING ldap_syslog_level
55 #define LDAP_LEVEL_NOTICE ldap_syslog_level
56 #define LDAP_LEVEL_INFO ldap_syslog_level
57 #define LDAP_LEVEL_DEBUG ldap_syslog_level
58 #else /* !LDAP_DEBUG || !LDAP_SYSLOG */
59 #define LDAP_LEVEL_EMERG (7)
60 #define LDAP_LEVEL_ALERT (7)
61 #define LDAP_LEVEL_CRIT (7)
62 #define LDAP_LEVEL_ERR (7)
63 #define LDAP_LEVEL_WARNING (7)
64 #define LDAP_LEVEL_NOTICE (7)
65 #define LDAP_LEVEL_INFO (7)
66 #define LDAP_LEVEL_DEBUG (7)
67 #endif /* !LDAP_DEBUG || !LDAP_SYSLOG */
69 #else /* ! OLD_DEBUG */
70 /* map syslog onto LDAP severity levels */
72 #define LDAP_LEVEL_EMERG LOG_EMERG
73 #define LDAP_LEVEL_ALERT LOG_ALERT
74 #define LDAP_LEVEL_CRIT LOG_CRIT
75 #define LDAP_LEVEL_ERR LOG_ERR
76 #define LDAP_LEVEL_WARNING LOG_WARNING
77 #define LDAP_LEVEL_NOTICE LOG_NOTICE
78 #define LDAP_LEVEL_INFO LOG_INFO
79 #define LDAP_LEVEL_DEBUG LOG_DEBUG
80 #else /* ! LOG_DEBUG */
81 #define LDAP_LEVEL_EMERG (0)
82 #define LDAP_LEVEL_ALERT (1)
83 #define LDAP_LEVEL_CRIT (2)
84 #define LDAP_LEVEL_ERR (3)
85 #define LDAP_LEVEL_WARNING (4)
86 #define LDAP_LEVEL_NOTICE (5)
87 #define LDAP_LEVEL_INFO (6)
88 #define LDAP_LEVEL_DEBUG (7)
89 #endif /* ! LOG_DEBUG */
90 #endif /* ! OLD_DEBUG */
92 /* in case we need to reuse the unused bits of severity */
93 #define LDAP_LEVEL_MASK(s) ((s) & 0x7)
95 #define LDAP_LEVEL_MASK(s) (s)
99 #define LDAP_LEVEL_ENTRY (0x08) /* log function entry points */
100 #define LDAP_LEVEL_ARGS (0x10) /* log function call parameters */
101 #define LDAP_LEVEL_RESULTS (0x20) /* Log function results */
102 #define LDAP_LEVEL_DETAIL1 (0x40) /* log level 1 function operational details */
103 #define LDAP_LEVEL_DETAIL2 (0x80) /* Log level 2 function operational details */
104 /* end of (yet) unused */
106 /* original subsystem selection mechanism */
107 #define LDAP_DEBUG_TRACE 0x0001
108 #define LDAP_DEBUG_PACKETS 0x0002
109 #define LDAP_DEBUG_ARGS 0x0004
110 #define LDAP_DEBUG_CONNS 0x0008
111 #define LDAP_DEBUG_BER 0x0010
112 #define LDAP_DEBUG_FILTER 0x0020
113 #define LDAP_DEBUG_CONFIG 0x0040
114 #define LDAP_DEBUG_ACL 0x0080
115 #define LDAP_DEBUG_STATS 0x0100
116 #define LDAP_DEBUG_STATS2 0x0200
117 #define LDAP_DEBUG_SHELL 0x0400
118 #define LDAP_DEBUG_PARSE 0x0800
119 #if 0 /* no longer used (nor supported) */
120 #define LDAP_DEBUG_CACHE 0x1000
121 #define LDAP_DEBUG_INDEX 0x2000
123 #define LDAP_DEBUG_SYNC 0x4000
125 #define LDAP_DEBUG_NONE 0x8000
126 #define LDAP_DEBUG_ANY (-1)
128 /* debugging stuff */
131 * This is a bogus extern declaration for the compiler. No need to ensure
132 * a 'proper' dllimport.
135 extern int ldap_debug;
136 #endif /* !ldap_debug */
139 extern int ldap_syslog;
140 extern int ldap_syslog_level;
143 #define syslog eb_syslog
144 extern void eb_syslog(int pri, const char *fmt, ...);
145 #endif /* HAVE_EBCDIC */
147 #endif /* LDAP_SYSLOG */
149 /* this doesn't below as part of ldap.h */
152 #define LogTest(level) ( ( ldap_debug | ldap_syslog ) & (level) )
153 #define LogExpand(level, severity, args) \
155 if ( ldap_debug & (level) ) \
156 lutil_debug( ldap_debug, (level), args ); \
157 if ( ldap_syslog & (level) ) \
158 syslog( LDAP_LEVEL_MASK((severity)), args ); \
161 #else /* ! LDAP_SYSLOG */
163 #define LogTest(level) ( ldap_debug & (level) )
164 #define LogExpand(level, severity, args) \
166 if ( ldap_debug & (level) ) \
167 lutil_debug( ldap_debug, (level), args ); \
170 #endif /* ! LDAP_SYSLOG */
171 #else /* ! LDAP_DEBUG */
173 /* TODO: in case LDAP_DEBUG is undefined, make sure logs with appropriate
174 * severity gets thru anyway */
175 #define LogTest(level) ( 0 )
176 #define LogExpand(level, severity, args) ((void) 0)
178 #endif /* ! LDAP_DEBUG */
181 #define Log0(level, severity, fmt) \
182 LogExpand((level), (severity), (fmt))
183 #define Log1(level, severity, fmt, a1) \
184 LogExpand((level), (severity), (fmt) LogArg(a1))
185 #define Log2(level, severity, fmt, a1, a2) \
186 LogExpand((level), (severity), (fmt) LogArg(a1) LogArg(a2))
187 #define Log3(level, severity, fmt, a1, a2, a3) \
188 LogExpand((level), (severity), (fmt) LogArg(a1) LogArg(a2) LogArg(a3))
189 #define Log4(level, severity, fmt, a1, a2, a3, a4) \
190 LogExpand((level), (severity), (fmt) LogArg(a1) LogArg(a2) LogArg(a3) \
192 #define Log5(level, severity, fmt, a1, a2, a3, a4, a5) \
193 LogExpand((level), (severity), (fmt) LogArg(a1) LogArg(a2) LogArg(a3) \
194 LogArg(a4) LogArg(a5))
195 #define Debug(level, fmt, a1, a2, a3) \
196 LogExpand((level), ldap_syslog_level, (fmt) \
197 LogArg(a1) LogArg(a2) LogArg(a3))
199 /* Actually now in liblber/debug.c */
200 LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
202 LDAP_LUTIL_F(void) lutil_debug LDAP_P((
203 int debug, int level,
204 const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
206 #ifdef LDAP_DEFINE_LDAP_DEBUG
207 /* This struct matches the head of ldapoptions in <ldap-int.h> */
208 struct ldapoptions_prefix {
213 (*(int *) ((char *)&ldap_int_global_options \
214 + offsetof(struct ldapoptions_prefix, ldo_debug)))
217 LDAP_V ( struct ldapoptions ) ldap_int_global_options;
218 #endif /* LDAP_DEFINE_LDAP_DEBUG */
222 #endif /* LDAP_LOG_H */