allow textual log levels in command line

This commit is contained in:
Pierangelo Masarati 2005-08-08 14:01:40 +00:00
parent d463430295
commit cccf35c749
3 changed files with 37 additions and 4 deletions

View File

@ -1945,6 +1945,26 @@ slap_loglevel_register( slap_mask_t m, struct berval *s )
return rc;
}
int
str2loglevel( const char *s, int *l )
{
int i;
if ( loglevel_ops == NULL ) {
loglevel_init();
}
i = verb_to_mask( s, loglevel_ops );
if ( BER_BVISNULL( &loglevel_ops[ i ].word) ) {
return -1;
}
*l = loglevel_ops[ i ].mask;
return 0;
}
static int
config_loglevel(ConfigArgs *c) {
int i;
@ -1980,14 +2000,12 @@ config_loglevel(ConfigArgs *c) {
return( 1 );
}
} else {
int j = verb_to_mask(c->argv[i], loglevel_ops);
if(BER_BVISNULL(&loglevel_ops[j].word)) {
if ( str2loglevel( c->argv[i], &level ) ) {
sprintf( c->msg, "<%s> unknown level", c->argv[0] );
Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
c->log, c->msg, c->argv[i]);
return( 1 );
}
level = loglevel_ops[j].mask;
}
ldap_syslog |= level;
}

View File

@ -386,7 +386,21 @@ int main( int argc, char **argv )
case 'd': /* set debug level and 'do not detach' flag */
no_detach = 1;
#ifdef LDAP_DEBUG
slap_debug |= atoi( optarg );
if ( optarg != NULL && optarg[ 0 ] != '-' && !isdigit( optarg[ 0 ] ) )
{
int level;
if ( str2loglevel( optarg, &level ) ) {
fprintf( stderr,
"unrecognized log level "
"\"%s\"\n", optarg );
goto destroy;
}
slap_debug |= level;
} else {
slap_debug |= atoi( optarg );
}
#else
if ( atoi( optarg ) != 0 )
fputs( "must compile with LDAP_DEBUG for debugging\n",

View File

@ -368,6 +368,7 @@ LDAP_SLAPD_F (int) overlay_op_walk LDAP_P((
* bconfig.c
*/
LDAP_SLAPD_F (int) slap_loglevel_register LDAP_P (( slap_mask_t m, struct berval *s ));
LDAP_SLAPD_F (int) str2loglevel LDAP_P(( const char *s, int *l ));
/*
* ch_malloc.c