]> git.sur5r.net Git - openldap/blob - include/ldap_log.h
Extended ber_mem functions, add context argument.
[openldap] / include / ldap_log.h
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted only as authorized by the OpenLDAP
8  * Public License.  A copy of this license is available at
9  * http://www.OpenLDAP.org/license.html or in file LICENSE in the
10  * top-level directory of the distribution.
11  */
12 /* Portions
13  * Copyright (c) 1990 Regents of the University of Michigan.
14  * All rights reserved.
15  *
16  * Redistribution and use in source and binary forms are permitted
17  * provided that this notice is preserved and that due credit is given
18  * to the University of Michigan at Ann Arbor. The name of the University
19  * may not be used to endorse or promote products derived from this
20  * software without specific prior written permission. This software
21  * is provided ``as is'' without express or implied warranty.
22  */
23
24 #ifndef _LDAP_LOG_H
25 #define _LDAP_LOG_H
26
27 #include <stdio.h>
28 #include <ldap_cdefs.h>
29
30 LDAP_BEGIN_DECL
31
32 /*
33  * While it's not important that the subsystem number are
34  * contiguous, it is important that the LDAP_SUBSYS_NUM accurately
35  * reflect the number of subsystems and LDAP_SUBSYS_MAX reflect
36  * the largest subsystem number.
37  */
38 #define LDAP_SUBSYS_NUM 20
39 #define LDAP_SUBSYS_MAX 19
40
41 #define LDAP_SUBSYS_GLOBAL      0
42 #define LDAP_SUBSYS_OPERATION   1
43 #define LDAP_SUBSYS_TRANSPORT   2
44 #define LDAP_SUBSYS_CONNECTION  3
45 #define LDAP_SUBSYS_FILTER      4
46 #define LDAP_SUBSYS_BER         5
47 #define LDAP_SUBSYS_CONFIG      6
48 #define LDAP_SUBSYS_ACL         7
49 #define LDAP_SUBSYS_CACHE       8
50 #define LDAP_SUBSYS_INDEX       9
51 #define LDAP_SUBSYS_LDIF        10
52 #define LDAP_SUBSYS_TOOLS       11
53 #define LDAP_SUBSYS_SLAPD       12
54 #define LDAP_SUBSYS_SLURPD      13
55 #define LDAP_SUBSYS_BACKEND     14
56 #define LDAP_SUBSYS_BACK_BDB    15
57 #define LDAP_SUBSYS_BACK_LDBM   16
58 #define LDAP_SUBSYS_BACK_LDAP   17
59 #define LDAP_SUBSYS_BACK_META   18
60 #define LDAP_SUBSYS_BACK_MON    19
61
62 /*
63  * debug reporting levels.
64  *
65  * They start with the syslog levels, and
66  * go down in importance.  The normal
67  * debugging levels begin with LDAP_LEVEL_ENTRY
68  *
69  */
70 #define LDAP_LEVEL_EMERG       0
71 #define LDAP_LEVEL_ALERT       1
72 #define LDAP_LEVEL_CRIT        2
73 #define LDAP_LEVEL_ERR         3
74 #define LDAP_LEVEL_WARNING     4
75 #define LDAP_LEVEL_NOTICE      5
76 #define LDAP_LEVEL_INFO        6
77 #define LDAP_LEVEL_ENTRY       7  /* log function entry points */
78 #define LDAP_LEVEL_ARGS        8  /* log function call parameters */
79 #define LDAP_LEVEL_RESULTS     9  /* Log function results */
80 #define LDAP_LEVEL_DETAIL1    10  /* log level 1 function operational details */
81 #define LDAP_LEVEL_DETAIL2    11  /* Log level 2 function operational details */
82
83 #define LDAP_DEBUG_TRACE        0x0001
84 #define LDAP_DEBUG_PACKETS      0x0002
85 #define LDAP_DEBUG_ARGS         0x0004
86 #define LDAP_DEBUG_CONNS        0x0008
87 #define LDAP_DEBUG_BER          0x0010
88 #define LDAP_DEBUG_FILTER       0x0020
89 #define LDAP_DEBUG_CONFIG       0x0040
90 #define LDAP_DEBUG_ACL          0x0080
91 #define LDAP_DEBUG_STATS        0x0100
92 #define LDAP_DEBUG_STATS2       0x0200
93 #define LDAP_DEBUG_SHELL        0x0400
94 #define LDAP_DEBUG_PARSE        0x0800
95 #define LDAP_DEBUG_CACHE    0x1000
96 #define LDAP_DEBUG_INDEX    0x2000
97
98 #define LDAP_DEBUG_NONE         0x8000
99 #define LDAP_DEBUG_ANY          -1
100
101 /* debugging stuff */
102 #ifdef LDAP_DEBUG
103
104     /*
105      * This is a bogus extern declaration for the compiler. No need to ensure
106      * a 'proper' dllimport.
107      */
108 #   ifndef ldap_debug
109      extern int ldap_debug;
110 #   endif /* !ldap_debug */
111
112 #   ifdef LDAP_SYSLOG
113     extern int  ldap_syslog;
114     extern int  ldap_syslog_level;
115 #   endif /* LDAP_SYSLOG */
116
117 /* this doesn't below as part of ldap.h */
118 #   ifdef LDAP_SYSLOG
119 #   define Debug( level, fmt, arg1, arg2, arg3 )        \
120         do { \
121                 if ( ldap_debug & (level) ) \
122                         lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
123                 if ( ldap_syslog & (level) ) \
124                         syslog( ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) ); \
125         } while ( 0 )
126
127 #   else
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         } while ( 0 )
133 #   endif
134
135 #else /* LDAP_DEBUG */
136 #   define Debug( level, fmt, arg1, arg2, arg3 )
137
138 #endif /* LDAP_DEBUG */
139
140 #ifdef NEW_LOGGING
141 extern int ldap_loglevels[LDAP_SUBSYS_NUM];
142 #define LDAP_LOG(a, b, fmt, arg1, arg2, arg3) do {\
143         if (ldap_loglevels[LDAP_SUBSYS_##a] >= LDAP_LEVEL_##b || \
144                 ldap_loglevels[LDAP_SUBSYS_GLOBAL] >= LDAP_LEVEL_##b)\
145                    lutil_log (LDAP_SUBSYS_##a, LDAP_LEVEL_##b, fmt, arg1, arg2, arg3); \
146         } while (0)
147
148
149 #define LDAP_LOGS_TEST(a, b) \
150         (ldap_loglevels[LDAP_SUBSYS_##a] >= LDAP_LEVEL_##b || \
151          ldap_loglevels[LDAP_SUBSYS_GLOBAL] >= LDAP_LEVEL_##b)
152
153 #endif /* LDAP_LOG */
154
155 #ifndef LDAP_LOG
156 #define LDAP_LOG(a, b, fmt, arg1, arg2, arg3)
157 #endif
158
159 LDAP_LUTIL_F(int) lutil_mnem2level LDAP_P(( const char *level ));
160 LDAP_LUTIL_F(void) lutil_log_initialize LDAP_P((
161         int argc, char **argv ));
162 LDAP_LUTIL_F(int) lutil_set_debug_level LDAP_P((
163         const char *subsys, int level ));
164 LDAP_LUTIL_F(void) lutil_log LDAP_P((
165         const int subsys, int level, const char *fmt, ... ));
166
167 LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
168
169
170 LDAP_LUTIL_F(void) lutil_debug LDAP_P((
171         int debug, int level,
172         const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
173
174 LDAP_END_DECL
175
176 #endif /* _LDAP_LOG_H */