diff --git a/doc/man/man5/lloadd.conf.5 b/doc/man/man5/lloadd.conf.5 index c7295b4c06..7a938043f5 100644 --- a/doc/man/man5/lloadd.conf.5 +++ b/doc/man/man5/lloadd.conf.5 @@ -180,6 +180,19 @@ messages exposed by the configuration parameter. Specifying a logfile copies messages to both stderr and the logfile. .TP +.B logfile-only on | off +Specify that debug messages should only go to the configured logfile, and +not to stderr. +.TP +.B logfile-rotate +Specify automatic rotation for the configured logfile as the maximum +number of old logfiles to retain, a maximum size in megabytes to allow a +logfile to grow before rotation, and a maximum age in hours for a logfile +to be used before rotation. The maximum number must be in the range 1-99. +Setting Mbytes or hours to zero disables the size or age check, respectively. +At least one of Mbytes or hours must be non-zero. By default no automatic +rotation will be performed. +.TP .B loglevel [...] Specify the level at which debugging statements and operation statistics should be syslogged (currently logged to the diff --git a/servers/lloadd/config.c b/servers/lloadd/config.c index 1e5dd169f5..65bb8d33e1 100644 --- a/servers/lloadd/config.c +++ b/servers/lloadd/config.c @@ -157,6 +157,8 @@ enum { CFG_CONCUR, CFG_THREADS, CFG_LOGFILE, + CFG_LOGFILE_ONLY, + CFG_LOGFILE_ROTATE, CFG_MIRRORMODE, CFG_IOTHREADS, CFG_MAXBUF_CLIENT, @@ -292,6 +294,16 @@ static ConfigTable config_back_cf_table[] = { &config_generic, NULL, NULL, NULL }, + { "logfile-only", "on|off", 2, 2, 0, + ARG_ON_OFF|ARG_MAGIC|CFG_LOGFILE_ONLY, + &config_generic, + NULL, NULL, NULL + }, + { "logfile-rotate", "max> value_string; - logfile = fopen( logfileName, "w" ); - if ( logfile ) lutil_debug_file( logfile ); + int rc = logfile_open( c->value_string ); + ch_free( c->value_string ); + return rc; + } break; + + case CFG_LOGFILE_ONLY: + slap_debug = slap_debug_orig; + if ( c->value_int ) { + slap_debug |= config_syslog; + ldap_syslog = 0; + } else { + ldap_syslog = config_syslog; + } + logfile_only = c->value_int; + break; + + case CFG_LOGFILE_ROTATE: { + unsigned lf_max, lf_mbyte, lf_hour; + if ( lutil_atoux( &lf_max, c->argv[1], 0 ) != 0 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> " + "invalid max value \"%s\"", + c->argv[0], c->argv[1] ); + goto fail; + } + if ( !lf_max || lf_max > 99 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> " + "invalid max value \"%s\" must be 1-99", + c->argv[0], c->argv[1] ); + goto fail; + } + if ( lutil_atoux( &lf_mbyte, c->argv[2], 0 ) != 0 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> " + "invalid Mbyte value \"%s\"", + c->argv[0], c->argv[2] ); + goto fail; + } + if ( lutil_atoux( &lf_hour, c->argv[3], 0 ) != 0 ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> " + "invalid hours value \"%s\"", + c->argv[0], c->argv[3] ); + goto fail; + } + if ( !lf_mbyte && !lf_hour ) { + snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> " + "Mbyte and hours cannot both be zero", + c->argv[0] ); + goto fail; + } + logfile_max = lf_max; + logfile_fslimit = lf_mbyte * 1048576; /* Megabytes to bytes */ + logfile_age = lf_hour * 3600; /* hours to seconds */ } break; case CFG_RESCOUNT: @@ -2065,8 +2126,6 @@ loglevel_print( FILE *out ) return 0; } -static int config_syslog; - static int config_loglevel( ConfigArgs *c ) { @@ -2104,7 +2163,12 @@ config_loglevel( ConfigArgs *c ) config_syslog = 0; } if ( slapMode & SLAP_SERVER_MODE ) { - ldap_syslog = config_syslog; + if ( logfile_only ) { + slap_debug = slap_debug_orig | config_syslog; + ldap_syslog = 0; + } else { + ldap_syslog = config_syslog; + } } return 0; }