xref: /netbsd-src/external/bsd/openldap/dist/include/ldap_log.h (revision b5677b36047b601b9addaaa494a58ceae82c2a6c)
1 /* $OpenLDAP: pkg/ldap/include/ldap_log.h,v 1.40.2.5 2008/02/11 23:26:40 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2008 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 
26 #ifndef LDAP_LOG_H
27 #define LDAP_LOG_H
28 
29 #include <stdio.h>
30 #include <ldap_cdefs.h>
31 
32 LDAP_BEGIN_DECL
33 
34 /*
35  * debug reporting levels.
36  *
37  * They start with the syslog levels, and
38  * go down in importance.  The normal
39  * debugging levels begin with LDAP_LEVEL_ENTRY
40  *
41  */
42 
43 /*
44  * The "OLD_DEBUG" means that all logging occurs at LOG_DEBUG
45  */
46 
47 #ifdef OLD_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 */
68 
69 #else /* ! OLD_DEBUG */
70 /* map syslog onto LDAP severity levels */
71 #ifdef LOG_DEBUG
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 */
91 #if 0
92 /* in case we need to reuse the unused bits of severity */
93 #define	LDAP_LEVEL_MASK(s)	((s) & 0x7)
94 #else
95 #define	LDAP_LEVEL_MASK(s)	(s)
96 #endif
97 
98 /* (yet) unused */
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 */
105 
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
122 #endif
123 #define LDAP_DEBUG_SYNC		0x4000
124 
125 #define LDAP_DEBUG_NONE		0x8000
126 #define LDAP_DEBUG_ANY		-1
127 
128 /* debugging stuff */
129 #ifdef LDAP_DEBUG
130     /*
131      * This is a bogus extern declaration for the compiler. No need to ensure
132      * a 'proper' dllimport.
133      */
134 #ifndef ldap_debug
135 extern int	ldap_debug;
136 #endif /* !ldap_debug */
137 
138 #ifdef LDAP_SYSLOG
139 extern int	ldap_syslog;
140 extern int	ldap_syslog_level;
141 
142 #ifdef HAVE_EBCDIC
143 #define syslog	eb_syslog
144 extern void eb_syslog(int pri, const char *fmt, ...);
145 #endif /* HAVE_EBCDIC */
146 
147 #endif /* LDAP_SYSLOG */
148 
149 /* this doesn't below as part of ldap.h */
150 #ifdef LDAP_SYSLOG
151 #define Log0( level, severity, fmt )	\
152 	do { \
153 		if ( ldap_debug & (level) ) \
154 			lutil_debug( ldap_debug, (level), (fmt) ); \
155 		if ( ldap_syslog & (level) ) \
156 			syslog( LDAP_LEVEL_MASK((severity)), (fmt) ); \
157 	} while ( 0 )
158 #define Log1( level, severity, fmt, arg1 )	\
159 	do { \
160 		if ( ldap_debug & (level) ) \
161 			lutil_debug( ldap_debug, (level), (fmt), (arg1) ); \
162 		if ( ldap_syslog & (level) ) \
163 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1) ); \
164 	} while ( 0 )
165 #define Log2( level, severity, fmt, arg1, arg2 ) \
166 	do { \
167 		if ( ldap_debug & (level) ) \
168 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2) ); \
169 		if ( ldap_syslog & (level) ) \
170 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2) ); \
171 	} while ( 0 )
172 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) \
173 	do { \
174 		if ( ldap_debug & (level) ) \
175 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
176 		if ( ldap_syslog & (level) ) \
177 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3) ); \
178 	} while ( 0 )
179 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) \
180 	do { \
181 		if ( ldap_debug & (level) ) \
182 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
183 		if ( ldap_syslog & (level) ) \
184 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
185 	} while ( 0 )
186 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) \
187 	do { \
188 		if ( ldap_debug & (level) ) \
189 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
190 		if ( ldap_syslog & (level) ) \
191 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
192 	} while ( 0 )
193 #define Debug( level, fmt, arg1, arg2, arg3 )	\
194 	Log3( (level), ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) )
195 #define LogTest(level) ( ( ldap_debug | ldap_syslog ) & (level) )
196 
197 #else /* ! LDAP_SYSLOG */
198 #define Log0( level, severity, fmt ) \
199 	do { \
200 		if ( ldap_debug & (level) ) \
201 	    		lutil_debug( ldap_debug, (level), (fmt) ); \
202 	} while ( 0 )
203 #define Log1( level, severity, fmt, arg1 ) \
204 	do { \
205 		if ( ldap_debug & (level) ) \
206 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1) ); \
207 	} while ( 0 )
208 #define Log2( level, severity, fmt, arg1, arg2 ) \
209 	do { \
210 		if ( ldap_debug & (level) ) \
211 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2) ); \
212 	} while ( 0 )
213 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) \
214 	do { \
215 		if ( ldap_debug & (level) ) \
216 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
217 	} while ( 0 )
218 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) \
219 	do { \
220 		if ( ldap_debug & (level) ) \
221 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
222 	} while ( 0 )
223 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) \
224 	do { \
225 		if ( ldap_debug & (level) ) \
226 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
227 	} while ( 0 )
228 #define Debug( level, fmt, arg1, arg2, arg3 ) \
229 		Log3( (level), 0, (fmt), (arg1), (arg2), (arg3) )
230 #define LogTest(level) ( ldap_debug & (level) )
231 #endif /* ! LDAP_SYSLOG */
232 #else /* ! LDAP_DEBUG */
233 /* TODO: in case LDAP_DEBUG is undefined, make sure logs with appropriate
234  * severity gets thru anyway */
235 #define Log0( level, severity, fmt ) ((void)0)
236 #define Log1( level, severity, fmt, arg1 ) ((void)0)
237 #define Log2( level, severity, fmt, arg1, arg2 ) ((void)0)
238 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) ((void)0)
239 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) ((void)0)
240 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) ((void)0)
241 #define Debug( level, fmt, arg1, arg2, arg3 ) ((void)0)
242 #define LogTest(level) ( 0 )
243 #endif /* ! LDAP_DEBUG */
244 
245 LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
246 
247 LDAP_LUTIL_F(void) lutil_debug LDAP_P((
248 	int debug, int level,
249 	const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
250 
251 LDAP_END_DECL
252 
253 #endif /* LDAP_LOG_H */
254