]> git.sur5r.net Git - openldap/commitdiff
allow textual log levels in command line
authorPierangelo Masarati <ando@openldap.org>
Mon, 8 Aug 2005 14:01:40 +0000 (14:01 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 8 Aug 2005 14:01:40 +0000 (14:01 +0000)
servers/slapd/bconfig.c
servers/slapd/main.c
servers/slapd/proto-slap.h

index 77d9065f01a8caa0240de2b29961af818a226f3d..291004fb6239ecba15b06b536366eeacf0d24201 100644 (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;
        }
index b607bdb912af24a499ea03448791ea47f7e54c7e..02dcd5009f220cf2ea189bde26854789274877a8 100644 (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",
index 24ab45ac70577f7a3395c182f0d1c04958222022..5ad9092de766b5f8545a5c4989df91913ed1b5a9 100644 (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