1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-18 03:00:59 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1999-06-22 06:52:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, 1998 by Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdarg.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "ldap_log.h"
|
|
|
|
#include "ldap_defaults.h"
|
2000-05-11 17:39:33 +08:00
|
|
|
#include "lber.h"
|
1999-06-22 06:52:28 +08:00
|
|
|
|
|
|
|
static FILE *log_file;
|
|
|
|
|
|
|
|
int lutil_debug_file( FILE *file )
|
|
|
|
{
|
1999-09-02 15:40:25 +08:00
|
|
|
log_file = file;
|
2000-05-11 17:39:33 +08:00
|
|
|
ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file );
|
1999-06-22 06:52:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void (lutil_debug)( int level, int debug, const char *fmt, ... )
|
|
|
|
{
|
|
|
|
char buffer[4096];
|
|
|
|
va_list vl;
|
|
|
|
|
|
|
|
if ( !(level & debug ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef HAVE_WINSOCK
|
|
|
|
if( log_file == NULL )
|
|
|
|
{
|
1999-06-22 06:59:23 +08:00
|
|
|
log_file = fopen( LDAP_RUNDIR LDAP_DIRSEP "openldap.log", "w" );
|
1999-06-22 06:52:28 +08:00
|
|
|
|
|
|
|
if ( log_file == NULL )
|
1999-06-22 06:59:23 +08:00
|
|
|
log_file = fopen( "openldap.log", "w" );
|
1999-06-22 06:52:28 +08:00
|
|
|
|
|
|
|
if ( log_file == NULL )
|
|
|
|
return;
|
2000-05-11 17:39:33 +08:00
|
|
|
|
|
|
|
ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file );
|
1999-06-22 06:52:28 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
va_start( vl, fmt );
|
|
|
|
|
1999-06-29 06:04:31 +08:00
|
|
|
#ifdef HAVE_VSNPRINTF
|
1999-06-22 06:52:28 +08:00
|
|
|
vsnprintf( buffer, sizeof(buffer), fmt, vl );
|
1999-06-29 06:04:31 +08:00
|
|
|
#else
|
|
|
|
vsprintf( buffer, fmt, vl );
|
|
|
|
#endif
|
1999-06-22 06:52:28 +08:00
|
|
|
buffer[sizeof(buffer)-1] = '\0';
|
|
|
|
|
|
|
|
if( log_file != NULL ) {
|
|
|
|
fputs( buffer, log_file );
|
|
|
|
fflush( log_file );
|
|
|
|
}
|
|
|
|
|
1999-06-29 09:02:48 +08:00
|
|
|
fputs( buffer, stderr );
|
1999-06-22 06:52:28 +08:00
|
|
|
va_end( vl );
|
|
|
|
}
|