mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-28 18:49:34 -05:00
ITS#9745 add config keyword for logfile format
This commit is contained in:
parent
61bc08deaf
commit
a1799a6e5e
9 changed files with 98 additions and 3 deletions
|
|
@ -176,6 +176,13 @@ effect until the server has been restarted.
|
|||
Specify a file for recording lloadd debug messages. By default these messages
|
||||
only go to stderr, are not recorded anywhere else, and are unrelated to
|
||||
messages exposed by the
|
||||
.TP
|
||||
.B logfile-format debug | syslog-utc | syslog-localtime
|
||||
Specify the prefix format for messages written to the logfile. The debug
|
||||
format is the normal format used for slapd debug messages, with a timestamp
|
||||
in hexadecimal, followed by a thread ID. The other options are to
|
||||
use syslog(3) style prefixes, with timestamps either in UTC or in the
|
||||
local timezone. The default is debug format.
|
||||
.B loglevel
|
||||
configuration parameter. Specifying a logfile copies messages to both stderr
|
||||
and the logfile.
|
||||
|
|
|
|||
|
|
@ -571,6 +571,13 @@ messages exposed by the
|
|||
configuration parameter. Specifying a logfile copies messages to both stderr
|
||||
and the logfile.
|
||||
.TP
|
||||
.B olcLogFileFormat: debug | syslog-utc | syslog-localtime
|
||||
Specify the prefix format for messages written to the logfile. The debug
|
||||
format is the normal format used for slapd debug messages, with a timestamp
|
||||
in hexadecimal, followed by a thread ID. The other options are to
|
||||
use syslog(3) style prefixes, with timestamps either in UTC or in the
|
||||
local timezone. The default is debug format.
|
||||
.TP
|
||||
.B olcLogFileOnly: TRUE | FALSE
|
||||
Specify that debug messages should only go to the configured logfile, and
|
||||
not to stderr.
|
||||
|
|
|
|||
|
|
@ -625,6 +625,13 @@ messages exposed by the
|
|||
configuration parameter. Specifying a logfile copies messages to both stderr
|
||||
and the logfile.
|
||||
.TP
|
||||
.B logfile-format debug | syslog-utc | syslog-localtime
|
||||
Specify the prefix format for messages written to the logfile. The debug
|
||||
format is the normal format used for slapd debug messages, with a timestamp
|
||||
in hexadecimal, followed by a thread ID. The other options are to
|
||||
use syslog(3) style prefixes, with timestamps either in UTC or in the
|
||||
local timezone. The default is debug format.
|
||||
.TP
|
||||
.B logfile-only on | off
|
||||
Specify that debug messages should only go to the configured logfile, and
|
||||
not to stderr.
|
||||
|
|
|
|||
|
|
@ -291,6 +291,11 @@ static ConfigTable config_back_cf_table[] = {
|
|||
&config_logging,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
{ "logfile-format", "debug|syslog-utc|syslog-localtime", 2, 2, 0,
|
||||
ARG_MAGIC|CFG_LOGFILE_FORMAT,
|
||||
&config_logging,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
{ "logfile-only", "on|off", 2, 2, 0,
|
||||
ARG_ON_OFF|ARG_MAGIC|CFG_LOGFILE_ONLY,
|
||||
&config_logging,
|
||||
|
|
|
|||
|
|
@ -483,6 +483,10 @@ static ConfigTable config_back_cf_table[] = {
|
|||
&config_logging, "( OLcfgGlAt:27 NAME 'olcLogFile' "
|
||||
"EQUALITY caseExactMatch "
|
||||
"SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
|
||||
{ "logfile-format", "debug|syslog-utc|syslog-localtime", 2, 2, 0, ARG_MAGIC|CFG_LOGFILE_FORMAT,
|
||||
&config_logging, "( OLcfgGlAt:104 NAME 'olcLogFileFormat' "
|
||||
"EQUALITY caseIgnoreMatch "
|
||||
"SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
|
||||
{ "logfile-only", "on|off", 2, 2, 0, ARG_ON_OFF|ARG_MAGIC|CFG_LOGFILE_ONLY,
|
||||
&config_logging, "( OLcfgGlAt:102 NAME 'olcLogFileOnly' "
|
||||
"EQUALITY booleanMatch "
|
||||
|
|
@ -984,7 +988,7 @@ static ConfigOCs cf_ocs[] = {
|
|||
"olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
|
||||
"olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
|
||||
"olcIndexIntLen $ "
|
||||
"olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
|
||||
"olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogFileFormat $ olcLogLevel $ "
|
||||
"olcLogFileOnly $ olcLogFileRotate $ olcMaxFilterDepth $ "
|
||||
"olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
|
||||
"olcPluginLogFile $ olcReadOnly $ olcReferral $ "
|
||||
|
|
|
|||
|
|
@ -40,7 +40,21 @@ static char logfile_suffix[sizeof(".xx.gz")];
|
|||
static char logfile_path[MAXPATHLEN - sizeof(logfile_suffix) -1];
|
||||
static long logfile_fslimit;
|
||||
static int logfile_age, logfile_only, logfile_max;
|
||||
static char *syslog_prefix;
|
||||
static int splen;
|
||||
|
||||
typedef enum { LFMT_DEFAULT, LFMT_DEBUG, LFMT_SYSLOG_UTC, LFMT_SYSLOG_LOCAL } LogFormat;
|
||||
static LogFormat logfile_format;
|
||||
|
||||
static slap_verbmasks logformat_key[] = {
|
||||
{ BER_BVC("default"), LFMT_DEFAULT },
|
||||
{ BER_BVC("debug"), LFMT_DEBUG },
|
||||
{ BER_BVC("syslog-utc"), LFMT_SYSLOG_UTC },
|
||||
{ BER_BVC("syslog-localtime"), LFMT_SYSLOG_LOCAL },
|
||||
{ BER_BVNULL, 0 }
|
||||
};
|
||||
|
||||
char *serverName;
|
||||
int slap_debug_orig;
|
||||
|
||||
ldap_pvt_thread_mutex_t logfile_mutex;
|
||||
|
|
@ -51,6 +65,8 @@ static int logfile_fd = -1;
|
|||
static char logpaths[2][MAXPATHLEN];
|
||||
static int logpathlen;
|
||||
|
||||
#define SYSLOG_STAMP "Mmm dd hh:mm:ss"
|
||||
|
||||
void
|
||||
slap_debug_print( const char *data )
|
||||
{
|
||||
|
|
@ -69,6 +85,7 @@ slap_debug_print( const char *data )
|
|||
#define gettime(tv) gettimeofday( tv, NULL )
|
||||
#endif
|
||||
|
||||
|
||||
gettime( &tv );
|
||||
iov[0].iov_base = prefix;
|
||||
iov[0].iov_len = sprintf( prefix, "%lx." TS " %p ",
|
||||
|
|
@ -93,6 +110,20 @@ slap_debug_print( const char *data )
|
|||
logfile_open( logfile_path );
|
||||
}
|
||||
}
|
||||
|
||||
if ( logfile_format > LFMT_DEBUG ) {
|
||||
struct tm tm;
|
||||
if ( logfile_format == LFMT_SYSLOG_UTC )
|
||||
ldap_pvt_gmtime( &tv.tv_sec, &tm );
|
||||
else
|
||||
ldap_pvt_localtime( &tv.tv_sec, &tm );
|
||||
strftime( syslog_prefix, sizeof( SYSLOG_STAMP ),
|
||||
"%b %d %T", &tm );
|
||||
syslog_prefix[ sizeof( SYSLOG_STAMP )-1 ] = ' ';
|
||||
iov[0].iov_base = syslog_prefix;
|
||||
iov[0].iov_len = splen;
|
||||
}
|
||||
|
||||
len = writev( logfile_fd, iov, 2 );
|
||||
if ( len > 0 )
|
||||
logfile_fsize += len;
|
||||
|
|
@ -575,6 +606,13 @@ config_logging(ConfigArgs *c) {
|
|||
rc = 1;
|
||||
}
|
||||
break;
|
||||
case CFG_LOGFILE_FORMAT:
|
||||
if ( logfile_format ) {
|
||||
value_add_one( &c->rvalue_vals, &logformat_key[logfile_format].word );
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
break;
|
||||
case CFG_LOGFILE_ONLY:
|
||||
c->value_int = logfile_only;
|
||||
break;
|
||||
|
|
@ -611,6 +649,12 @@ config_logging(ConfigArgs *c) {
|
|||
logfile_close();
|
||||
break;
|
||||
|
||||
case CFG_LOGFILE_FORMAT:
|
||||
logfile_format = 0;
|
||||
ch_free( syslog_prefix );
|
||||
syslog_prefix = NULL;
|
||||
break;
|
||||
|
||||
case CFG_LOGFILE_ONLY:
|
||||
/* remove loglevel from debuglevel */
|
||||
slap_debug = slap_debug_orig;
|
||||
|
|
@ -672,6 +716,26 @@ reset:
|
|||
ch_free( c->value_string );
|
||||
break;
|
||||
|
||||
case CFG_LOGFILE_FORMAT: {
|
||||
int len;
|
||||
i = verb_to_mask( c->argv[1], logformat_key );
|
||||
|
||||
if ( BER_BVISNULL( &logformat_key[ i ].word ) ) {
|
||||
snprintf( c->cr_msg, sizeof( c->cr_msg ), "<%s> unknown format", c->argv[0] );
|
||||
Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
|
||||
c->log, c->cr_msg, c->argv[1]);
|
||||
return( 1 );
|
||||
}
|
||||
if ( syslog_prefix )
|
||||
ch_free( syslog_prefix );
|
||||
len = strlen( global_host ) + 1 + strlen( serverName ) + 1 + sizeof("[123456789]:") +
|
||||
sizeof( SYSLOG_STAMP );
|
||||
syslog_prefix = ch_malloc( len );
|
||||
splen = sprintf( syslog_prefix, SYSLOG_STAMP " %s %s[%d]: ", global_host, serverName, getpid() );
|
||||
logfile_format = logformat_key[i].mask;
|
||||
}
|
||||
break;
|
||||
|
||||
case CFG_LOGFILE_ONLY:
|
||||
logfile_only = c->value_int;
|
||||
goto reset;
|
||||
|
|
|
|||
|
|
@ -238,7 +238,6 @@ int main( int argc, char **argv )
|
|||
|
||||
char *configfile = NULL;
|
||||
char *configdir = NULL;
|
||||
char *serverName;
|
||||
int serverMode = SLAP_SERVER_MODE;
|
||||
|
||||
struct sync_cookie *scp = NULL;
|
||||
|
|
|
|||
|
|
@ -1246,6 +1246,7 @@ LDAP_SLAPD_F (void)
|
|||
slap_check_unknown_level LDAP_P(( char *levelstr, int level ));
|
||||
LDAP_SLAPD_V(ldap_pvt_thread_mutex_t) logfile_mutex;
|
||||
LDAP_SLAPD_V(int) slap_debug_orig;
|
||||
LDAP_SLAPD_V (char *) serverName;
|
||||
|
||||
/*
|
||||
* main.c
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ enum {
|
|||
CFG_LOGLEVEL = 1,
|
||||
CFG_LOGFILE,
|
||||
CFG_LOGFILE_ROTATE,
|
||||
CFG_LOGFILE_ONLY
|
||||
CFG_LOGFILE_ONLY,
|
||||
CFG_LOGFILE_FORMAT
|
||||
};
|
||||
|
||||
extern ConfigDriver config_logging;
|
||||
|
|
|
|||
Loading…
Reference in a new issue