Check debug level before invoking debug routine, slight optimization

This commit is contained in:
Howard Chu 2001-09-21 17:53:16 +00:00
parent c0c9c47032
commit 2f6b7e3d43
3 changed files with 17 additions and 12 deletions

View file

@ -111,6 +111,7 @@ LDAP_BEGIN_DECL
# ifdef LDAP_SYSLOG # ifdef LDAP_SYSLOG
# define Debug( level, fmt, arg1, arg2, arg3 ) \ # define Debug( level, fmt, arg1, arg2, arg3 ) \
do { \ do { \
if ( ldap_debug & (level) ) \
lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \ lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
if ( ldap_syslog & (level) ) \ if ( ldap_syslog & (level) ) \
syslog( ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) ); \ syslog( ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) ); \
@ -118,7 +119,10 @@ LDAP_BEGIN_DECL
# else # else
# define Debug( level, fmt, arg1, arg2, arg3 ) \ # 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 # endif
#ifndef LDAP_LOG #ifndef LDAP_LOG

View file

@ -16,7 +16,7 @@
typedef void (*BER_LOG_FN) LDAP_P((FILE *file, char *subsys, int level, const char *fmt, va_list vl)); 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; 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; 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, ... ) int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
{ {
char buf[ 1024 ]; char buf[ 1024 ];

View file

@ -819,6 +819,8 @@ sb_debug_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
ber_slen_t ret; ber_slen_t ret;
ret = LBER_SBIOD_READ_NEXT( sbiod, buf, len ); ret = LBER_SBIOD_READ_NEXT( sbiod, buf, len );
if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
{
if ( ret < 0 ) { if ( ret < 0 ) {
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt, "%sread: want=%ld error=%s\n", (char *)sbiod->sbiod_pvt,
@ -831,6 +833,7 @@ sb_debug_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
(const char *)buf, ret ); (const char *)buf, ret );
} }
}
return ret; return ret;
} }
@ -840,6 +843,8 @@ sb_debug_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
ber_slen_t ret; ber_slen_t ret;
ret = LBER_SBIOD_WRITE_NEXT( sbiod, buf, len ); ret = LBER_SBIOD_WRITE_NEXT( sbiod, buf, len );
if (sbiod->sbiod_sb->sb_debug & LDAP_DEBUG_PACKETS)
{
if ( ret < 0 ) { if ( ret < 0 ) {
ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_printf( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
"%swrite: want=%ld error=%s\n", "%swrite: want=%ld error=%s\n",
@ -853,6 +858,7 @@ sb_debug_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len )
ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug, ber_log_bprint( LDAP_DEBUG_PACKETS, sbiod->sbiod_sb->sb_debug,
(const char *)buf, ret ); (const char *)buf, ret );
} }
}
return ret; return ret;
} }