--- openldap-cvs/include/ldap_log.h	1 Jan 2005 19:49:42 -0000	1.36
+++ openldap-cvs/include/ldap_log.h	14 Jul 2005 20:05:41 -0000
@@ -52,23 +52,24 @@
 #define LDAP_LEVEL_DETAIL1    10  /* log level 1 function operational details */
 #define LDAP_LEVEL_DETAIL2    11  /* Log level 2 function operational details */
 
-#define LDAP_DEBUG_TRACE	0x0001
-#define LDAP_DEBUG_PACKETS	0x0002
-#define LDAP_DEBUG_ARGS		0x0004
-#define LDAP_DEBUG_CONNS	0x0008
-#define LDAP_DEBUG_BER		0x0010
-#define LDAP_DEBUG_FILTER	0x0020
-#define LDAP_DEBUG_CONFIG	0x0040
-#define LDAP_DEBUG_ACL		0x0080
-#define LDAP_DEBUG_STATS	0x0100
-#define LDAP_DEBUG_STATS2	0x0200
-#define LDAP_DEBUG_SHELL	0x0400
-#define LDAP_DEBUG_PARSE	0x0800
-#define LDAP_DEBUG_CACHE    0x1000
-#define LDAP_DEBUG_INDEX    0x2000
-#define LDAP_DEBUG_SYNC		0x4000
+#define LDAP_DEBUG_TRACE	0x00001
+#define LDAP_DEBUG_PACKETS	0x00002
+#define LDAP_DEBUG_ARGS		0x00004
+#define LDAP_DEBUG_CONNS	0x00008
+#define LDAP_DEBUG_BER		0x00010
+#define LDAP_DEBUG_FILTER	0x00020
+#define LDAP_DEBUG_CONFIG	0x00040
+#define LDAP_DEBUG_ACL		0x00080
+#define LDAP_DEBUG_STATS	0x00100
+#define LDAP_DEBUG_STATS2	0x00200
+#define LDAP_DEBUG_SHELL	0x00400
+#define LDAP_DEBUG_PARSE	0x00800
+#define LDAP_DEBUG_CACHE	0x01000
+#define LDAP_DEBUG_INDEX	0x02000
+#define LDAP_DEBUG_SYNC		0x04000
 
-#define LDAP_DEBUG_NONE		0x8000
+#define LDAP_DEBUG_NONE		0x08000
+#define LDAP_DEBUG_SLAPI	0x10000
 #define LDAP_DEBUG_ANY		-1
 
 /* debugging stuff */
--- openldap-cvs/servers/slapd/bconfig.c	12 Jul 2005 12:25:15 -0000	1.106
+++ openldap-cvs/servers/slapd/bconfig.c	14 Jul 2005 20:05:42 -0000
@@ -375,11 +375,7 @@
 		"( OLcfgGlAt:38 NAME 'olcPlugin' "
 			"SYNTAX OMsDirectoryString )", NULL, NULL },
 	{ "pluginlog", "filename", 2, 2, 0,
-#ifdef LDAP_SLAPI
-		ARG_STRING, &slapi_log_file,
-#else
 		ARG_IGNORED, NULL,
-#endif
 		"( OLcfgGlAt:39 NAME 'olcPluginLogFile' "
 			"SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
 	{ "readonly", "on|off", 2, 2, 0, ARG_MAY_DB|ARG_ON_OFF|ARG_MAGIC|CFG_RO,
--- openldap-cvs/servers/slapd/slapi/plugin.c	1 Mar 2005 20:16:44 -0000	1.29
+++ openldap-cvs/servers/slapd/slapi/plugin.c	14 Jul 2005 20:05:43 -0000
@@ -78,6 +78,8 @@
 
 	pPlugin = slapi_pblock_new();
 	if ( pPlugin == NULL ) {
+		slapi_log_error( SLAPI_LOG_FATAL, "plugin_pblock_new", 
+				"Not enough memory to allocate new pblock" );
 		rc = LDAP_NO_MEMORY;
 		goto done;
 	}
@@ -94,6 +96,8 @@
 
 	av2 = ldap_charray_dup( argv );
 	if ( !av2 ) {
+		slapi_log_error( SLAPI_LOG_FATAL, "plugin_pblock_new",
+				"Not enough memory to duplicate arguments" );
 		rc = LDAP_NO_MEMORY;
 		goto done;
 	}
@@ -613,17 +617,25 @@
 	assert( pLdHandle );
 
 	if ( lt_dlinit() ) {
+		slapi_log_error( SLAPI_LOG_FATAL, "slapi_int_load_plugin",
+				"failed to init dynamic linker: %s", lt_dlerror() );
 		return LDAP_LOCAL_ERROR;
 	}
 
 	/* load in the module */
 	*pLdHandle = lt_dlopen( path );
 	if ( *pLdHandle == NULL ) {
+		slapi_log_error( SLAPI_LOG_FATAL, "slapi_int_load_plugin", 
+				"failed to load '%s': %s\n",
+				path, lt_dlerror() ); 
 		return LDAP_LOCAL_ERROR;
 	}
 
 	fpInitFunc = (SLAPI_FUNC)lt_dlsym( *pLdHandle, initfunc );
 	if ( fpInitFunc == NULL ) {
+		slapi_log_error( SLAPI_LOG_FATAL, "slapi_int_load_plugin", 
+				"failed to get init func '%s' for plugin '%s': %s\n",
+				initfunc, path, lt_dlerror() );
 		lt_dlclose( *pLdHandle );
 		return LDAP_LOCAL_ERROR;
 	}
@@ -631,6 +643,9 @@
 	if ( doInit == TRUE ) {
 		rc = ( *fpInitFunc )( pPlugin );
 		if ( rc != LDAP_SUCCESS ) {
+			slapi_log_error( SLAPI_LOG_FATAL, "slapi_int_load_plugin", 
+					"plugin '%s' failed to init\n",
+					path );
 			lt_dlclose( *pLdHandle );
 		}
 
@@ -704,7 +719,7 @@
 	int		numPluginArgc = 0;
 
 	if ( argc < 4 ) {
-		fprintf( stderr,
+		slapi_log_error( SLAPI_LOG_FATAL, "slapi_int_read_config",
 			"%s: line %d: missing arguments "
 			"in \"plugin <plugin_type> <lib_path> "
 			"<init_function> [<arguments>]\" line\n",
@@ -721,7 +736,8 @@
 	} else if ( strcasecmp( argv[1], "object" ) == 0 ) {
 		iType = SLAPI_PLUGIN_OBJECT;
 	} else {
-		fprintf( stderr, "%s: line %d: invalid plugin type \"%s\".\n",
+		slapi_log_error( SLAPI_LOG_FATAL, "slapi_int_read_config",
+				"file %s: line %d: invalid plugin type \"%s\".\n",
 				fname, lineno, argv[1] );
 		return 1;
 	}
@@ -808,11 +824,6 @@
 		return -1;
 	}
 
-	slapi_log_file = ch_strdup( LDAP_RUNDIR LDAP_DIRSEP "errors" );
-	if ( slapi_log_file == NULL ) {
-		return -1;
-	}
-
 	if ( slapi_int_init_object_extensions() != 0 ) {
 		return -1;
 	}
--- openldap-cvs/servers/slapd/slapi/printmsg.c	1 Jan 2005 19:49:59 -0000	1.14
+++ openldap-cvs/servers/slapd/slapi/printmsg.c	14 Jul 2005 20:05:43 -0000
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <ac/errno.h>
 
+#include <ldap_log.h>
 #include <ldap.h>
 #include <ldap_config.h>
 #include <slap.h>
@@ -36,7 +37,6 @@
 
 /* Single threads access to routine */
 ldap_pvt_thread_mutex_t slapi_printmessage_mutex; 
-char			*slapi_log_file = NULL;
 int			slapi_log_level = SLAPI_LOG_PLUGIN;
 
 int 
@@ -47,47 +47,24 @@
 	va_list		arglist ) 
 {
 	int		rc = 0;
-	FILE		*fp = NULL;
 
-	char		timeStr[100];
-	struct tm	*ltm;
-	time_t		currentTime;
+	static char	vstr[1024];
+	int		vstrlen;
 
 	assert( subsystem != NULL );
 	assert( fmt != NULL );
 
 	ldap_pvt_thread_mutex_lock( &slapi_printmessage_mutex ) ;
+	
 
 	/* for now, we log all severities */
 	if ( level <= slapi_log_level ) {
-		fp = fopen( slapi_log_file, "a" );
-		if ( fp == NULL) {
-			rc = -1;
-			goto done;
-		}
-
-		/*
-		* FIXME: could block
-		*/
-		while ( lockf( fileno( fp ), F_LOCK, 0 ) != 0 ) {
-			/* DO NOTHING */ ;
-		}
-
-		time( &currentTime );
-		ltm = localtime( &currentTime );
-		strftime( timeStr, sizeof(timeStr), "%x %X", ltm );
-		fputs( timeStr, fp );
-
-		fprintf( fp, " %s: ", subsystem );
-		vfprintf( fp, fmt, arglist );
-		if ( fmt[ strlen( fmt ) - 1 ] != '\n' ) {
-			fputs( "\n", fp );
-		}
-		fflush( fp );
 
-		lockf( fileno( fp ), F_ULOCK, 0 );
 
-		fclose( fp );
+		vstrlen = vsnprintf(vstr,1024, fmt, arglist);
+		if ( vstr[vstrlen] == '\n' ) vstr[vstrlen]=0;
+				
+		Debug( LDAP_DEBUG_SLAPI, "%s: %s\n", subsystem, vstr, 0 );
 
 	} else {
 		rc = -1;
