]> git.sur5r.net Git - openldap/blob - include/ldap_log.h
299e25f24af10cf574fc98112dc84b5bbb3e713d
[openldap] / include / ldap_log.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  * 
4  * Copyright 1998-2004 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  * While it's not important that the subsystem number are
36  * contiguous, it is important that the LDAP_SUBSYS_NUM accurately
37  * reflect the number of subsystems and LDAP_SUBSYS_MAX reflect
38  * the largest subsystem number.
39  */
40 #define LDAP_SUBSYS_NUM 20
41 #define LDAP_SUBSYS_MAX 19
42
43 #define LDAP_SUBSYS_GLOBAL      0
44 #define LDAP_SUBSYS_OPERATION   1
45 #define LDAP_SUBSYS_TRANSPORT   2
46 #define LDAP_SUBSYS_CONNECTION  3
47 #define LDAP_SUBSYS_FILTER      4
48 #define LDAP_SUBSYS_BER         5
49 #define LDAP_SUBSYS_CONFIG      6
50 #define LDAP_SUBSYS_ACL         7
51 #define LDAP_SUBSYS_CACHE       8
52 #define LDAP_SUBSYS_INDEX       9
53 #define LDAP_SUBSYS_LDIF        10
54 #define LDAP_SUBSYS_TOOLS       11
55 #define LDAP_SUBSYS_SLAPD       12
56 #define LDAP_SUBSYS_SLURPD      13
57 #define LDAP_SUBSYS_BACKEND     14
58 #define LDAP_SUBSYS_BACK_BDB    15
59 #define LDAP_SUBSYS_BACK_LDBM   16
60 #define LDAP_SUBSYS_BACK_LDAP   17
61 #define LDAP_SUBSYS_BACK_META   18
62 #define LDAP_SUBSYS_BACK_MON    19
63
64 /*
65  * debug reporting levels.
66  *
67  * They start with the syslog levels, and
68  * go down in importance.  The normal
69  * debugging levels begin with LDAP_LEVEL_ENTRY
70  *
71  */
72 #define LDAP_LEVEL_EMERG       0
73 #define LDAP_LEVEL_ALERT       1
74 #define LDAP_LEVEL_CRIT        2
75 #define LDAP_LEVEL_ERR         3
76 #define LDAP_LEVEL_WARNING     4
77 #define LDAP_LEVEL_NOTICE      5
78 #define LDAP_LEVEL_INFO        6
79 #define LDAP_LEVEL_ENTRY       7  /* log function entry points */
80 #define LDAP_LEVEL_ARGS        8  /* log function call parameters */
81 #define LDAP_LEVEL_RESULTS     9  /* Log function results */
82 #define LDAP_LEVEL_DETAIL1    10  /* log level 1 function operational details */
83 #define LDAP_LEVEL_DETAIL2    11  /* Log level 2 function operational details */
84
85 #define LDAP_DEBUG_TRACE        0x0001
86 #define LDAP_DEBUG_PACKETS      0x0002
87 #define LDAP_DEBUG_ARGS         0x0004
88 #define LDAP_DEBUG_CONNS        0x0008
89 #define LDAP_DEBUG_BER          0x0010
90 #define LDAP_DEBUG_FILTER       0x0020
91 #define LDAP_DEBUG_CONFIG       0x0040
92 #define LDAP_DEBUG_ACL          0x0080
93 #define LDAP_DEBUG_STATS        0x0100
94 #define LDAP_DEBUG_STATS2       0x0200
95 #define LDAP_DEBUG_SHELL        0x0400
96 #define LDAP_DEBUG_PARSE        0x0800
97 #define LDAP_DEBUG_CACHE    0x1000
98 #define LDAP_DEBUG_INDEX    0x2000
99 #define LDAP_DEBUG_SYNC         0x4000
100
101 #define LDAP_DEBUG_NONE         0x8000
102 #define LDAP_DEBUG_ANY          -1
103
104 /* debugging stuff */
105 #ifdef LDAP_DEBUG
106
107     /*
108      * This is a bogus extern declaration for the compiler. No need to ensure
109      * a 'proper' dllimport.
110      */
111 #   ifndef ldap_debug
112      extern int ldap_debug;
113 #   endif /* !ldap_debug */
114
115 #   ifdef LDAP_SYSLOG
116     extern int  ldap_syslog;
117     extern int  ldap_syslog_level;
118
119 #       ifdef HAVE_EBCDIC
120 #       define syslog   eb_syslog
121         extern void eb_syslog(int pri, const char *fmt, ...);
122 #       endif
123
124 #   endif /* LDAP_SYSLOG */
125
126 /* this doesn't below as part of ldap.h */
127 #   ifdef LDAP_SYSLOG
128 #   define Debug( level, fmt, arg1, arg2, arg3 )        \
129         do { \
130                 if ( ldap_debug & (level) ) \
131                         lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
132                 if ( ldap_syslog & (level) ) \
133                         syslog( ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) ); \
134         } while ( 0 )
135
136 #   else
137 #       define Debug( level, fmt, arg1, arg2, arg3 ) \
138         do { \
139                 if ( ldap_debug & (level) ) \
140                         lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
141         } while ( 0 )
142 #   endif
143
144 #else /* LDAP_DEBUG */
145 #   define Debug( level, fmt, arg1, arg2, arg3 )
146
147 #endif /* LDAP_DEBUG */
148
149 #ifdef NEW_LOGGING
150 extern int ldap_loglevels[LDAP_SUBSYS_NUM];
151
152 #ifdef LDAP_DEBUG
153
154 #define LDAP_LOG(a, b, fmt, arg1, arg2, arg3) do {\
155         if (ldap_loglevels[LDAP_SUBSYS_##a] >= LDAP_LEVEL_##b || \
156                 ldap_loglevels[LDAP_SUBSYS_GLOBAL] >= LDAP_LEVEL_##b)\
157                    lutil_log (LDAP_SUBSYS_##a, LDAP_LEVEL_##b, fmt, arg1, arg2, arg3); \
158         } while (0)
159
160
161 #define LDAP_LOGS_TEST(a, b) \
162         (ldap_loglevels[LDAP_SUBSYS_##a] >= LDAP_LEVEL_##b || \
163          ldap_loglevels[LDAP_SUBSYS_GLOBAL] >= LDAP_LEVEL_##b)
164
165 #endif /* LDAP_DEBUG */
166
167 #endif /* NEW_LOGGING */
168
169 #ifndef LDAP_LOG
170 #define LDAP_LOG(a, b, fmt, arg1, arg2, arg3)
171 #define LDAP_LOGS_TEST(a, b) 0
172 #endif
173
174 LDAP_LUTIL_F(int) lutil_mnem2level LDAP_P(( const char *level ));
175 LDAP_LUTIL_F(void) lutil_log_initialize LDAP_P((
176         int argc, char **argv ));
177 LDAP_LUTIL_F(int) lutil_set_debug_level LDAP_P((
178         const char *subsys, int level ));
179 LDAP_LUTIL_F(void) lutil_log LDAP_P((
180         const int subsys, int level, const char *fmt, ... ));
181
182 LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
183
184
185 LDAP_LUTIL_F(void) lutil_debug LDAP_P((
186         int debug, int level,
187         const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
188
189 LDAP_END_DECL
190
191 #endif /* _LDAP_LOG_H */