Back to index

openldap  2.4.31
ldap_log.h
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  * 
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
00016  * All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms are permitted
00019  * provided that this notice is preserved and that due credit is given
00020  * to the University of Michigan at Ann Arbor. The name of the University
00021  * may not be used to endorse or promote products derived from this
00022  * software without specific prior written permission. This software
00023  * is provided ``as is'' without express or implied warranty.
00024  */
00025 
00026 #ifndef LDAP_LOG_H
00027 #define LDAP_LOG_H
00028 
00029 #include <stdio.h>
00030 #include <ldap_cdefs.h>
00031 
00032 LDAP_BEGIN_DECL
00033 
00034 /*
00035  * debug reporting levels.
00036  *
00037  * They start with the syslog levels, and
00038  * go down in importance.  The normal
00039  * debugging levels begin with LDAP_LEVEL_ENTRY
00040  *
00041  */
00042 
00043 /*
00044  * The "OLD_DEBUG" means that all logging occurs at LOG_DEBUG
00045  */
00046 
00047 #ifdef OLD_DEBUG
00048 /* original behavior: all logging occurs at the same severity level */
00049 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
00050 #define LDAP_LEVEL_EMERG    ldap_syslog_level
00051 #define LDAP_LEVEL_ALERT    ldap_syslog_level
00052 #define LDAP_LEVEL_CRIT            ldap_syslog_level
00053 #define LDAP_LEVEL_ERR             ldap_syslog_level
00054 #define LDAP_LEVEL_WARNING  ldap_syslog_level
00055 #define LDAP_LEVEL_NOTICE   ldap_syslog_level
00056 #define LDAP_LEVEL_INFO            ldap_syslog_level
00057 #define LDAP_LEVEL_DEBUG    ldap_syslog_level
00058 #else /* !LDAP_DEBUG || !LDAP_SYSLOG */
00059 #define LDAP_LEVEL_EMERG    (7)
00060 #define LDAP_LEVEL_ALERT    (7)
00061 #define LDAP_LEVEL_CRIT            (7)
00062 #define LDAP_LEVEL_ERR             (7)
00063 #define LDAP_LEVEL_WARNING  (7)
00064 #define LDAP_LEVEL_NOTICE   (7)
00065 #define LDAP_LEVEL_INFO            (7)
00066 #define LDAP_LEVEL_DEBUG    (7)
00067 #endif /* !LDAP_DEBUG || !LDAP_SYSLOG */
00068 
00069 #else /* ! OLD_DEBUG */
00070 /* map syslog onto LDAP severity levels */
00071 #ifdef LOG_DEBUG
00072 #define LDAP_LEVEL_EMERG    LOG_EMERG
00073 #define LDAP_LEVEL_ALERT    LOG_ALERT
00074 #define LDAP_LEVEL_CRIT            LOG_CRIT
00075 #define LDAP_LEVEL_ERR             LOG_ERR
00076 #define LDAP_LEVEL_WARNING  LOG_WARNING
00077 #define LDAP_LEVEL_NOTICE   LOG_NOTICE
00078 #define LDAP_LEVEL_INFO            LOG_INFO
00079 #define LDAP_LEVEL_DEBUG    LOG_DEBUG
00080 #else /* ! LOG_DEBUG */
00081 #define LDAP_LEVEL_EMERG    (0)
00082 #define LDAP_LEVEL_ALERT    (1)
00083 #define LDAP_LEVEL_CRIT            (2)
00084 #define LDAP_LEVEL_ERR             (3)
00085 #define LDAP_LEVEL_WARNING  (4)
00086 #define LDAP_LEVEL_NOTICE   (5)
00087 #define LDAP_LEVEL_INFO            (6)
00088 #define LDAP_LEVEL_DEBUG    (7)
00089 #endif /* ! LOG_DEBUG */
00090 #endif /* ! OLD_DEBUG */
00091 #if 0
00092 /* in case we need to reuse the unused bits of severity */
00093 #define       LDAP_LEVEL_MASK(s)   ((s) & 0x7)
00094 #else
00095 #define       LDAP_LEVEL_MASK(s)   (s)
00096 #endif
00097 
00098 /* (yet) unused */
00099 #define LDAP_LEVEL_ENTRY    (0x08) /* log function entry points */
00100 #define LDAP_LEVEL_ARGS            (0x10) /* log function call parameters */
00101 #define LDAP_LEVEL_RESULTS  (0x20) /* Log function results */
00102 #define LDAP_LEVEL_DETAIL1  (0x40) /* log level 1 function operational details */
00103 #define LDAP_LEVEL_DETAIL2  (0x80) /* Log level 2 function operational details */
00104 /* end of (yet) unused */
00105 
00106 /* original subsystem selection mechanism */
00107 #define LDAP_DEBUG_TRACE    0x0001
00108 #define LDAP_DEBUG_PACKETS  0x0002
00109 #define LDAP_DEBUG_ARGS            0x0004
00110 #define LDAP_DEBUG_CONNS    0x0008
00111 #define LDAP_DEBUG_BER             0x0010
00112 #define LDAP_DEBUG_FILTER   0x0020
00113 #define LDAP_DEBUG_CONFIG   0x0040
00114 #define LDAP_DEBUG_ACL             0x0080
00115 #define LDAP_DEBUG_STATS    0x0100
00116 #define LDAP_DEBUG_STATS2   0x0200
00117 #define LDAP_DEBUG_SHELL    0x0400
00118 #define LDAP_DEBUG_PARSE    0x0800
00119 #if 0 /* no longer used (nor supported) */
00120 #define LDAP_DEBUG_CACHE    0x1000
00121 #define LDAP_DEBUG_INDEX    0x2000
00122 #endif
00123 #define LDAP_DEBUG_SYNC            0x4000
00124 
00125 #define LDAP_DEBUG_NONE            0x8000
00126 #define LDAP_DEBUG_ANY             (-1)
00127 
00128 /* debugging stuff */
00129 #ifdef LDAP_DEBUG
00130     /*
00131      * This is a bogus extern declaration for the compiler. No need to ensure
00132      * a 'proper' dllimport.
00133      */
00134 #ifndef ldap_debug
00135 extern int    ldap_debug;
00136 #endif /* !ldap_debug */
00137 
00138 #ifdef LDAP_SYSLOG
00139 extern int    ldap_syslog;
00140 extern int    ldap_syslog_level;
00141 
00142 #ifdef HAVE_EBCDIC
00143 #define syslog       eb_syslog
00144 extern void eb_syslog(int pri, const char *fmt, ...);
00145 #endif /* HAVE_EBCDIC */
00146 
00147 #endif /* LDAP_SYSLOG */
00148 
00149 /* this doesn't below as part of ldap.h */
00150 #ifdef LDAP_SYSLOG
00151 #define Log0( level, severity, fmt )      \
00152        do { \
00153               if ( ldap_debug & (level) ) \
00154                      lutil_debug( ldap_debug, (level), (fmt) ); \
00155               if ( ldap_syslog & (level) ) \
00156                      syslog( LDAP_LEVEL_MASK((severity)), (fmt) ); \
00157        } while ( 0 )
00158 #define Log1( level, severity, fmt, arg1 )       \
00159        do { \
00160               if ( ldap_debug & (level) ) \
00161                      lutil_debug( ldap_debug, (level), (fmt), (arg1) ); \
00162               if ( ldap_syslog & (level) ) \
00163                      syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1) ); \
00164        } while ( 0 )
00165 #define Log2( level, severity, fmt, arg1, arg2 ) \
00166        do { \
00167               if ( ldap_debug & (level) ) \
00168                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2) ); \
00169               if ( ldap_syslog & (level) ) \
00170                      syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2) ); \
00171        } while ( 0 )
00172 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) \
00173        do { \
00174               if ( ldap_debug & (level) ) \
00175                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
00176               if ( ldap_syslog & (level) ) \
00177                      syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3) ); \
00178        } while ( 0 )
00179 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) \
00180        do { \
00181               if ( ldap_debug & (level) ) \
00182                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
00183               if ( ldap_syslog & (level) ) \
00184                      syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
00185        } while ( 0 )
00186 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) \
00187        do { \
00188               if ( ldap_debug & (level) ) \
00189                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
00190               if ( ldap_syslog & (level) ) \
00191                      syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
00192        } while ( 0 )
00193 #define Debug( level, fmt, arg1, arg2, arg3 )    \
00194        Log3( (level), ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) )
00195 #define LogTest(level) ( ( ldap_debug | ldap_syslog ) & (level) )
00196 
00197 #else /* ! LDAP_SYSLOG */
00198 #define Log0( level, severity, fmt ) \
00199        do { \
00200               if ( ldap_debug & (level) ) \
00201                      lutil_debug( ldap_debug, (level), (fmt) ); \
00202        } while ( 0 )
00203 #define Log1( level, severity, fmt, arg1 ) \
00204        do { \
00205               if ( ldap_debug & (level) ) \
00206                      lutil_debug( ldap_debug, (level), (fmt), (arg1) ); \
00207        } while ( 0 )
00208 #define Log2( level, severity, fmt, arg1, arg2 ) \
00209        do { \
00210               if ( ldap_debug & (level) ) \
00211                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2) ); \
00212        } while ( 0 )
00213 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) \
00214        do { \
00215               if ( ldap_debug & (level) ) \
00216                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
00217        } while ( 0 )
00218 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) \
00219        do { \
00220               if ( ldap_debug & (level) ) \
00221                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
00222        } while ( 0 )
00223 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) \
00224        do { \
00225               if ( ldap_debug & (level) ) \
00226                      lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
00227        } while ( 0 )
00228 #define Debug( level, fmt, arg1, arg2, arg3 ) \
00229               Log3( (level), 0, (fmt), (arg1), (arg2), (arg3) )
00230 #define LogTest(level) ( ldap_debug & (level) )
00231 #endif /* ! LDAP_SYSLOG */
00232 #else /* ! LDAP_DEBUG */
00233 /* TODO: in case LDAP_DEBUG is undefined, make sure logs with appropriate
00234  * severity gets thru anyway */
00235 #define Log0( level, severity, fmt ) ((void)0)
00236 #define Log1( level, severity, fmt, arg1 ) ((void)0)
00237 #define Log2( level, severity, fmt, arg1, arg2 ) ((void)0)
00238 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) ((void)0)
00239 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) ((void)0)
00240 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) ((void)0)
00241 #define Debug( level, fmt, arg1, arg2, arg3 ) ((void)0)
00242 #define LogTest(level) ( 0 )
00243 #endif /* ! LDAP_DEBUG */
00244 
00245 /* Actually now in liblber/debug.c */
00246 LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
00247 
00248 LDAP_LUTIL_F(void) lutil_debug LDAP_P((
00249        int debug, int level,
00250        const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
00251 
00252 #ifdef LDAP_DEFINE_LDAP_DEBUG
00253 /* This struct matches the head of ldapoptions in <ldap-int.h> */
00254 struct ldapoptions_prefix {
00255        short  ldo_valid;
00256        int           ldo_debug;
00257 };
00258 #define ldap_debug \
00259        (*(int *) ((char *)&ldap_int_global_options \
00260                + offsetof(struct ldapoptions_prefix, ldo_debug)))
00261 
00262 struct ldapoptions;
00263 LDAP_V ( struct ldapoptions ) ldap_int_global_options;
00264 #endif /* LDAP_DEFINE_LDAP_DEBUG */
00265 
00266 LDAP_END_DECL
00267 
00268 #endif /* LDAP_LOG_H */