From 6650f07f502bed1f9925e32561eda17f6f43b7e8 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 19 Dec 2005 22:55:30 +0000 Subject: [PATCH] allow (and use) symbolic names for syslog levels --- doc/man/man8/slapd.8 | 10 ++++++++++ servers/slapd/main.c | 28 ++++++++++++++++++++++++++-- tests/scripts/defines.sh | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/doc/man/man8/slapd.8 b/doc/man/man8/slapd.8 index 015905ad18..bb55fe7174 100644 --- a/doc/man/man8/slapd.8 +++ b/doc/man/man8/slapd.8 @@ -96,6 +96,16 @@ This option tells at what level debugging statements should be logged to the .BR syslog (8) facility. +The value can be any of +"EMERG", +"ALERT", +"CRIT", +"ERR", +"WARNING", +"NOTICE", +"INFO" or +"DEBUG", +defaulting to "DEBUG". .TP .BI \-n " service\-name" Specifies the service name for logging and other purposes. Defaults diff --git a/servers/slapd/main.c b/servers/slapd/main.c index f9dd88d893..bd58a36edc 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -483,8 +483,32 @@ int main( int argc, char **argv ) } case 's': /* set syslog level */ - if ( lutil_atoi( &ldap_syslog_level, optarg ) != 0 ) { - fprintf( stderr, "unable to parse syslog level \"%s\"", optarg ); + if ( !isdigit( optarg[ 0 ] ) ) { + slap_verbmasks str2syslog_level[] = { + { BER_BVC( "EMERG" ), LOG_EMERG }, + { BER_BVC( "ALERT" ), LOG_ALERT }, + { BER_BVC( "CRIT" ), LOG_CRIT }, + { BER_BVC( "ERR" ), LOG_ERR }, + { BER_BVC( "WARNING" ), LOG_WARNING }, + { BER_BVC( "NOTICE" ), LOG_NOTICE }, + { BER_BVC( "INFO" ), LOG_INFO }, + { BER_BVC( "DEBUG" ), LOG_DEBUG }, + { BER_BVNULL, 0 } + }; + int i = verb_to_mask( optarg, str2syslog_level ); + if ( BER_BVISNULL( &str2syslog_level[ i ].word ) ) { + Debug( LDAP_DEBUG_ANY, + "unknown syslog level \"%s\".\n", + optarg, 0, 0 ); + goto destroy; + } + + ldap_syslog_level = str2syslog_level[ i ].mask; + + } else if ( lutil_atoi( &ldap_syslog_level, optarg ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "unable to parse syslog level \"%s\".\n", + optarg, 0, 0 ); goto destroy; } break; diff --git a/tests/scripts/defines.sh b/tests/scripts/defines.sh index 170b23a720..58a33bc1e6 100755 --- a/tests/scripts/defines.sh +++ b/tests/scripts/defines.sh @@ -137,7 +137,7 @@ DIFF="diff -i" CMP="diff -i" BCMP="diff -iB" CMPOUT=/dev/null -SLAPD="../servers/slapd/slapd -s0" +SLAPD="../servers/slapd/slapd -sDEBUG" SLURPD=../servers/slurpd/slurpd LDAPPASSWD="$CLIENTDIR/ldappasswd $TOOLARGS" LDAPSASLSEARCH="$CLIENTDIR/ldapsearch $TOOLPROTO $LDAP_TOOLARGS -LLL" -- 2.39.5