]> git.sur5r.net Git - openldap/blob - include/ldap_log.h
Do not require ac/string.h for lber_pvt.h
[openldap] / include / ldap_log.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  * 
4  * Copyright 1998-2018 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
152 #define LogTest(level) ( ( ldap_debug | ldap_syslog ) & (level) )
153 #define LogExpand(level, severity, args) \
154         do { \
155                 if ( ldap_debug & (level) ) \
156                         lutil_debug( ldap_debug, (level), args ); \
157                 if ( ldap_syslog & (level) ) \
158                         syslog( LDAP_LEVEL_MASK((severity)), args ); \
159         } while ( 0 )
160
161 #else /* ! LDAP_SYSLOG */
162
163 #define LogTest(level) ( ldap_debug & (level) )
164 #define LogExpand(level, severity, args) \
165         do { \
166                 if ( ldap_debug & (level) ) \
167                         lutil_debug( ldap_debug, (level), args ); \
168         } while ( 0 )
169
170 #endif /* ! LDAP_SYSLOG */
171 #else /* ! LDAP_DEBUG */
172
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)
177
178 #endif /* ! LDAP_DEBUG */
179
180 #define LogArg ,
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) \
191                 LogArg(a4))
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 Log6(level, severity, fmt, a1, a2, a3, a4, a5, a6) \
196         LogExpand((level), (severity), (fmt) LogArg(a1) LogArg(a2) LogArg(a3) \
197                 LogArg(a4) LogArg(a5) LogArg(a6))
198 #define Log7(level, severity, fmt, a1, a2, a3, a4, a5, a6, a7) \
199         LogExpand((level), (severity), (fmt) LogArg(a1) LogArg(a2) LogArg(a3) \
200                 LogArg(a4) LogArg(a5) LogArg(a6) LogArg(a7))
201 #define Debug(level, fmt, a1, a2, a3) \
202         LogExpand((level), ldap_syslog_level, (fmt) \
203                 LogArg(a1) LogArg(a2) LogArg(a3))
204
205 /* Actually now in liblber/debug.c */
206 LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
207
208 LDAP_LUTIL_F(void) lutil_debug LDAP_P((
209         int debug, int level,
210         const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
211
212 #ifdef LDAP_DEFINE_LDAP_DEBUG
213 /* This struct matches the head of ldapoptions in <ldap-int.h> */
214 struct ldapoptions_prefix {
215         short   ldo_valid;
216         int             ldo_debug;
217 };
218 #define ldap_debug \
219         (*(int *) ((char *)&ldap_int_global_options \
220                  + offsetof(struct ldapoptions_prefix, ldo_debug)))
221
222 struct ldapoptions;
223 LDAP_V ( struct ldapoptions ) ldap_int_global_options;
224 #endif /* LDAP_DEFINE_LDAP_DEBUG */
225
226 LDAP_END_DECL
227
228 #endif /* LDAP_LOG_H */