]> git.sur5r.net Git - openldap/commitdiff
Check debug level before invoking debug routine, slight optimization
authorHoward Chu <hyc@openldap.org>
Fri, 21 Sep 2001 17:53:16 +0000 (17:53 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 21 Sep 2001 17:53:16 +0000 (17:53 +0000)
include/ldap_log.h
libraries/liblber/bprint.c
libraries/liblber/sockbuf.c

index caa4ee2d2cb311786b17801fe4f2ebca11b29ebd..455e29995cbe6fb5553fa19563b89f3ff7f85b5b 100644 (file)
@@ -111,14 +111,18 @@ LDAP_BEGIN_DECL
 #   ifdef LDAP_SYSLOG
 #   define Debug( level, fmt, arg1, arg2, arg3 )       \
        do { \
-               lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
+               if ( ldap_debug & (level) ) \
+                       lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
                if ( ldap_syslog & (level) ) \
                        syslog( ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) ); \
        } while ( 0 )
 
 #   else
 #       define Debug( level, fmt, arg1, arg2, arg3 ) \
-           lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) )
+       do { \
+               if ( ldap_debug & (level) ) \
+                       lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
+       } while ( 0 )
 #   endif
 
 #ifndef LDAP_LOG
index 13f0f2508d95418803b9a5e378d88ec7c9d2eefe..2d341b771a83155c46d5de8efeeaf2de948bcc06 100644 (file)
@@ -16,7 +16,7 @@
 
 typedef void (*BER_LOG_FN) LDAP_P((FILE *file, char *subsys, int level, const char *fmt, va_list vl));
 
-static int ber_log_check( int errlvl, int loglvl );
+#define        ber_log_check(errlvl, loglvl)   (errlvl & loglvl)
 
 BER_LOG_FN ber_int_log_proc = NULL;
 
@@ -102,11 +102,6 @@ int ber_pvt_log_output( char *subsystem, int level, const char *fmt, ... )
        return 1;
 }
        
-static int ber_log_check( int errlvl, int loglvl )
-{
-       return errlvl & loglvl ? 1 : 0;
-}
-
 int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
 {
        char buf[ 1024 ];
index 154c355fcc42266a4dbf8db9eec45c816ad8f93f..e201157433b6808ec62f4833b4b2606ad85403f7 100644 (file)
@@ -819,17 +819,20 @@ sb_debug_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
        ber_slen_t              ret;
 
        ret = LBER_SBIOD_READ_NEXT( sbiod, buf, len );
-       if ( ret < 0 ) {
+       if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
+       {
+           if ( ret < 0 ) {
                ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
                        "%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt,
                        (long)len, STRERROR( errno ) );
 
-       } else {
+           } else {
                ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
                        "%sread: want=%ld, got=%ld\n", (char *)sbiod->sbiod_pvt,
                        (long)len, (long)ret );
                ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
                        (const char *)buf, ret );
+           }
        }
        return ret;
 }
@@ -840,18 +843,21 @@ sb_debug_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
        ber_slen_t              ret;
 
        ret = LBER_SBIOD_WRITE_NEXT( sbiod, buf, len );
-       if ( ret < 0 ) {
+       if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
+       {
+           if ( ret < 0 ) {
                ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
                        "%swrite: want=%ld error=%s\n",
                        (char *)sbiod->sbiod_pvt, (long)len,
                        STRERROR( errno ) );
 
-       } else {
+           } else {
                ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
                        "%swrite: want=%ld, written=%ld\n",
                        (char *)sbiod->sbiod_pvt, (long)len, (long)ret );
                ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
                        (const char *)buf, ret );
+           }
        }
 
        return ret;