Commit e983616d authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

More NEW_LOGGING removal

parent 547ebf66
......@@ -673,12 +673,14 @@ tool_conn_setup( int not, void (*private_setup)( LDAP * ) )
if( ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &debug )
!= LBER_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LBER_OPT_DEBUG_LEVEL %d\n", debug );
fprintf( stderr,
"Could not set LBER_OPT_DEBUG_LEVEL %d\n", debug );
}
if( ldap_set_option( NULL, LDAP_OPT_DEBUG_LEVEL, &debug )
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, "Could not set LDAP_OPT_DEBUG_LEVEL %d\n", debug );
fprintf( stderr,
"Could not set LDAP_OPT_DEBUG_LEVEL %d\n", debug );
}
}
......
......@@ -572,8 +572,6 @@ main( int argc, char **argv )
prog = lutil_progname( "ldapsearch", argc, argv );
lutil_log_initialize(argc, argv);
if((def_tmpdir = getenv("TMPDIR")) == NULL &&
(def_tmpdir = getenv("TMP")) == NULL &&
(def_tmpdir = getenv("TEMP")) == NULL )
......
......@@ -31,36 +31,6 @@
LDAP_BEGIN_DECL
/*
* While it's not important that the subsystem number are
* contiguous, it is important that the LDAP_SUBSYS_NUM accurately
* reflect the number of subsystems and LDAP_SUBSYS_MAX reflect
* the largest subsystem number.
*/
#define LDAP_SUBSYS_NUM 20
#define LDAP_SUBSYS_MAX 19
#define LDAP_SUBSYS_GLOBAL 0
#define LDAP_SUBSYS_OPERATION 1
#define LDAP_SUBSYS_TRANSPORT 2
#define LDAP_SUBSYS_CONNECTION 3
#define LDAP_SUBSYS_FILTER 4
#define LDAP_SUBSYS_BER 5
#define LDAP_SUBSYS_CONFIG 6
#define LDAP_SUBSYS_ACL 7
#define LDAP_SUBSYS_CACHE 8
#define LDAP_SUBSYS_INDEX 9
#define LDAP_SUBSYS_LDIF 10
#define LDAP_SUBSYS_TOOLS 11
#define LDAP_SUBSYS_SLAPD 12
#define LDAP_SUBSYS_SLURPD 13
#define LDAP_SUBSYS_BACKEND 14
#define LDAP_SUBSYS_BACK_BDB 15
#define LDAP_SUBSYS_BACK_LDBM 16
#define LDAP_SUBSYS_BACK_LDAP 17
#define LDAP_SUBSYS_BACK_META 18
#define LDAP_SUBSYS_BACK_MON 19
/*
* debug reporting levels.
*
......@@ -103,7 +73,6 @@ LDAP_BEGIN_DECL
/* debugging stuff */
#ifdef LDAP_DEBUG
/*
* This is a bogus extern declaration for the compiler. No need to ensure
* a 'proper' dllimport.
......@@ -146,42 +115,13 @@ LDAP_BEGIN_DECL
#endif /* LDAP_DEBUG */
#ifdef NEW_LOGGING
extern int ldap_loglevels[LDAP_SUBSYS_NUM];
#ifdef LDAP_DEBUG
#define LDAP_LOG(a, b, fmt, arg1, arg2, arg3) do {\
if (ldap_loglevels[LDAP_SUBSYS_##a] >= LDAP_LEVEL_##b || \
ldap_loglevels[LDAP_SUBSYS_GLOBAL] >= LDAP_LEVEL_##b)\
lutil_log (LDAP_SUBSYS_##a, LDAP_LEVEL_##b, fmt, arg1, arg2, arg3); \
} while (0)
#define LDAP_LOGS_TEST(a, b) \
(ldap_loglevels[LDAP_SUBSYS_##a] >= LDAP_LEVEL_##b || \
ldap_loglevels[LDAP_SUBSYS_GLOBAL] >= LDAP_LEVEL_##b)
#endif /* LDAP_DEBUG */
#endif /* NEW_LOGGING */
#ifndef LDAP_LOG
#define LDAP_LOG(a, b, fmt, arg1, arg2, arg3)
#define LDAP_LOGS_TEST(a, b) 0
#endif
LDAP_LUTIL_F(int) lutil_mnem2level LDAP_P(( const char *level ));
LDAP_LUTIL_F(void) lutil_log_initialize LDAP_P((
int argc, char **argv ));
LDAP_LUTIL_F(int) lutil_set_debug_level LDAP_P((
const char *subsys, int level ));
LDAP_LUTIL_F(void) lutil_log LDAP_P((
const int subsys, int level, const char *fmt, ... ));
LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
LDAP_LUTIL_F(void) lutil_debug LDAP_P((
int debug, int level,
const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
......
......@@ -32,10 +32,7 @@
#include "lber.h"
#include "ldap_pvt.h"
int ldap_loglevels[LDAP_SUBSYS_NUM];
static FILE *log_file = NULL;
static int global_level = 0;
#ifdef LDAP_SYSLOG
static int use_syslog = 0;
......@@ -54,81 +51,6 @@ static int debug2syslog(int l) {
}
#endif
static char *debug_levels[] = {
"emergency", "alert", "critical",
"error", "warning", "notice",
"information", "entry", "args",
"results", "detail1", "detail2",
NULL };
static char *debug_subsys[LDAP_SUBSYS_NUM] = {
"GLOBAL", "OPERATION", "TRANSPORT",
"CONNECTION", "FILTER", "BER",
"CONFIG", "ACL", "CACHE", "INDEX",
"LDIF", "TOOLS", "SLAPD", "SLURPD",
"BACKEND", "BACK_BDB", "BACK_LDBM",
"BACK_LDAP", "BACK_META", "BACK_MON" };
int lutil_mnem2subsys( const char *subsys )
{
int i;
for( i = 0; i < LDAP_SUBSYS_NUM; i++ ) {
if ( !strcasecmp( subsys, debug_subsys[i] ) ) {
return i;
}
}
return -1;
}
void lutil_set_all_backends( int level )
{
int i;
for( i = 0; i < LDAP_SUBSYS_NUM; i++ ) {
if ( !strncasecmp( "BACK_", debug_subsys[i], sizeof("BACK_")-1 ) ) {
ldap_loglevels[i] = level;
}
}
}
int lutil_mnem2level( const char *level )
{
int i;
for( i = 0; debug_levels[i] != NULL; i++ ) {
if ( !strcasecmp( level, debug_levels[i] ) ) {
return i;
}
}
return -1;
}
static int addSubsys( const char *subsys, int level )
{
int subsys_num;
if ( !strcasecmp( subsys, "BACKEND" ) ) {
lutil_set_all_backends( level );
return level;
} else {
subsys_num = lutil_mnem2subsys(subsys);
if(subsys_num < 0) {
fprintf(stderr, _("Unknown Subsystem name [ %s ] - Discarded\n"),
subsys);
fflush(stderr);
return -1;
}
ldap_loglevels[subsys_num] = level;
return level;
}
return -1;
}
int lutil_set_debug_level( const char* subsys, int level )
{
return( addSubsys( subsys, level ) );
}
int lutil_debug_file( FILE *file )
{
log_file = file;
......@@ -137,139 +59,6 @@ int lutil_debug_file( FILE *file )
return 0;
}
void lutil_log_int(
FILE* file,
const char *subsys, int level,
const char *fmt, va_list vl )
{
#ifdef HAVE_WINSOCK
time_t now;
struct tm *today;
#endif
#ifdef LDAP_SYSLOG
/* we're configured to use syslog */
if( use_syslog ) {
#ifdef HAVE_VSYSLOG
vsyslog( debug2syslog(level), fmt, vl );
#else
char data[4096];
vsnprintf( data, sizeof(data), fmt, vl );
syslog( debug2syslog(level), data );
#endif
return;
}
#endif
#if 0
#ifdef HAVE_WINSOCK
if( log_file == NULL ) {
log_file = fopen( LDAP_RUNDIR LDAP_DIRSEP "openldap.log", "w" );
if ( log_file == NULL ) {
log_file = fopen( "openldap.log", "w" );
if ( log_file == NULL ) return;
}
ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, log_file );
}
#endif
#endif
if( file == NULL ) {
/*
* Use stderr unless file was specified via:
* ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file)
*/
file = stderr;
}
#ifdef HAVE_WINSOCK
/*
* Stick the time in the buffer to output when using Winsock
* as NT can't pipe to a timestamp program like Unix can.
* This, of course, makes some logs hard to read.
*/
time( &now );
today = localtime( &now );
fprintf( file, "%4d%02d%02d:%02d:%02d:%02d ",
today->tm_year + 1900, today->tm_mon + 1,
today->tm_mday, today->tm_hour,
today->tm_min, today->tm_sec );
#endif
/*
* format the output data.
*/
fprintf(file, "\n%s:: ", subsys );
vfprintf( file, fmt, vl );
fflush( file );
}
/*
* The primary logging routine. Takes the subsystem being logged from, the
* level of the log output and the format and data. Send this on to the
* internal routine with the print file, if any.
*/
void lutil_log( const int subsys, int level, const char *fmt, ... )
{
FILE* outfile = NULL;
va_list vl;
va_start( vl, fmt );
ber_get_option( NULL, LBER_OPT_LOG_PRINT_FILE, &outfile );
lutil_log_int( outfile, debug_subsys[subsys], level, fmt, vl );
va_end( vl );
}
void lutil_log_initialize(int argc, char **argv)
{
int i;
/*
* Start by setting the hook for the libraries to use this logging
* routine.
*/
ber_set_option( NULL, LBER_OPT_LOG_PROC, (void*)lutil_log_int );
if ( argc == 0 ) return;
/*
* Now go through the command line options to set the debugging
* levels
*/
for( i = 0; i < argc; i++ ) {
char *next = argv[i];
if ( i < argc-1 && next[0] == '-' && next[1] == 'd' ) {
char subsys[64];
int level;
char *optarg = argv[i+1];
char *index = strchr( optarg, '=' );
if ( index != NULL ) {
*index = 0;
strcpy ( subsys, optarg );
level = atoi( index+1 );
if ( level <= 0 ) level = lutil_mnem2level( index + 1 );
lutil_set_debug_level( subsys, level );
*index = '=';
} else {
global_level = atoi( optarg );
ldap_loglevels[0] = global_level;
/*
* if a negative number was used, make the global level the
* maximum sane level.
*/
if ( global_level < 0 ) {
global_level = 65535;
ldap_loglevels[0] = 65535;
}
}
}
}
}
void (lutil_debug)( int debug, int level, const char *fmt, ... )
{
char buffer[4096];
......
......@@ -1345,25 +1345,6 @@ restrict_unknown:;
if( value_add( &default_referral, vals ) )
return LDAP_OTHER;
/* start of a new database definition */
} else if ( strcasecmp( cargv[0], "debug" ) == 0 ) {
int level;
if ( cargc < 3 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: Error in debug directive, \"debug subsys level\"\n",
fname, lineno, 0 );
return( 1 );
}
level = strtol( cargv[2], &next, 10 );
if ( next == NULL || next[0] != '\0' ){
Debug( LDAP_DEBUG_ANY,
"%s: line %d: unable to parse level \"%s\" in debug directive, "
"\"debug <subsys> <level>\"\n", fname, lineno , cargv[2] );
return( 1 );
}
if ( level <= 0 ) level = lutil_mnem2level( cargv[2] );
lutil_set_debug_level( cargv[1], level );
/* specify an Object Identifier macro */
} else if ( strcasecmp( cargv[0], "objectidentifier" ) == 0 ) {
rc = parse_oidm( fname, lineno, cargc, cargv );
......
......@@ -501,7 +501,6 @@ unhandled_option:;
(void) ldap_pvt_thread_initialize();
lutil_set_debug_level( "slapd", slap_debug );
ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
ldif_debug = slap_debug;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment