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.
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.
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.
&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,
&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 "
"olcIndexSubstrIfMaxLen $ olcIndexSubstrIfMinLen $ "
"olcIndexSubstrAnyLen $ olcIndexSubstrAnyStep $ olcIndexHash64 $ "
"olcIndexIntLen $ "
- "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogLevel $ "
+ "olcListenerThreads $ olcLocalSSF $ olcLogFile $ olcLogFileFormat $ olcLogLevel $ "
"olcLogFileOnly $ olcLogFileRotate $ olcMaxFilterDepth $ "
"olcPasswordCryptSaltFormat $ olcPasswordHash $ olcPidFile $ "
"olcPluginLogFile $ olcReadOnly $ olcReferral $ "
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;
static char logpaths[2][MAXPATHLEN];
static int logpathlen;
+#define SYSLOG_STAMP "Mmm dd hh:mm:ss"
+
void
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 ",
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;
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;
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;
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;
char *configfile = NULL;
char *configdir = NULL;
- char *serverName;
int serverMode = SLAP_SERVER_MODE;
struct sync_cookie *scp = NULL;
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
CFG_LOGLEVEL = 1,
CFG_LOGFILE,
CFG_LOGFILE_ROTATE,
- CFG_LOGFILE_ONLY
+ CFG_LOGFILE_ONLY,
+ CFG_LOGFILE_FORMAT
};
extern ConfigDriver config_logging;