Переглянути джерело

Ticket 48038 - logging should be pluggable

Description:  We need to pass in a logging function to nunc-stans,
              so we can log nunc-stan information in the DS errors
              log.  There are also "log start" and "log_close"
              functions that can be passed in as well.

              If a log function is not set in the thrpool config, then
              the logging will be sent to syslog.

https://fedorahosted.org/389/ticket/48038/

Reviewed by: rmeggins(Thanks!)
Mark Reynolds 10 роки тому
батько
коміт
3b7c2bb0c7

+ 22 - 21
ldap/include/ldaplog.h

@@ -47,28 +47,29 @@
 extern "C" {
 #endif
 
-#define LDAP_DEBUG_TRACE	0x00001		/*     1 */
-#define LDAP_DEBUG_PACKETS	0x00002		/*     2 */
-#define LDAP_DEBUG_ARGS		0x00004		/*     4 */
-#define LDAP_DEBUG_CONNS	0x00008		/*     8 */
-#define LDAP_DEBUG_BER		0x00010		/*    16 */
-#define LDAP_DEBUG_FILTER	0x00020		/*    32 */
-#define LDAP_DEBUG_CONFIG	0x00040		/*    64 */
-#define LDAP_DEBUG_ACL		0x00080		/*   128 */
-#define LDAP_DEBUG_STATS	0x00100		/*   256 */
-#define LDAP_DEBUG_STATS2	0x00200		/*   512 */
-#define LDAP_DEBUG_SHELL	0x00400		/*  1024 */
-#define LDAP_DEBUG_PARSE	0x00800		/*  2048 */
-#define LDAP_DEBUG_HOUSE        0x01000		/*  4096 */
-#define LDAP_DEBUG_REPL         0x02000		/*  8192 */
-#define LDAP_DEBUG_ANY          0x04000		/* 16384 */
-#define LDAP_DEBUG_CACHE        0x08000		/* 32768 */
-#define LDAP_DEBUG_PLUGIN	0x10000		/* 65536 */
-#define LDAP_DEBUG_TIMING	0x20000		/*131072 */
-#define LDAP_DEBUG_ACLSUMMARY	0x40000		/*262144 */
-#define LDAP_DEBUG_BACKLDBM		0x80000		/*524288 */
+#define LDAP_DEBUG_TRACE      0x000001  /*       1 */
+#define LDAP_DEBUG_PACKETS    0x000002  /*       2 */
+#define LDAP_DEBUG_ARGS       0x000004  /*       4 */
+#define LDAP_DEBUG_CONNS      0x000008  /*       8 */
+#define LDAP_DEBUG_BER        0x000010  /*      16 */
+#define LDAP_DEBUG_FILTER     0x000020  /*      32 */
+#define LDAP_DEBUG_CONFIG     0x000040  /*      64 */
+#define LDAP_DEBUG_ACL        0x000080  /*     128 */
+#define LDAP_DEBUG_STATS      0x000100  /*     256 */
+#define LDAP_DEBUG_STATS2     0x000200  /*     512 */
+#define LDAP_DEBUG_SHELL      0x000400  /*    1024 */
+#define LDAP_DEBUG_PARSE      0x000800  /*    2048 */
+#define LDAP_DEBUG_HOUSE      0x001000  /*    4096 */
+#define LDAP_DEBUG_REPL       0x002000  /*    8192 */
+#define LDAP_DEBUG_ANY        0x004000  /*   16384 */
+#define LDAP_DEBUG_CACHE      0x008000  /*   32768 */
+#define LDAP_DEBUG_PLUGIN     0x010000  /*   65536 */
+#define LDAP_DEBUG_TIMING     0x020000  /*  131072 */
+#define LDAP_DEBUG_ACLSUMMARY 0x040000  /*  262144 */
+#define LDAP_DEBUG_BACKLDBM   0x080000  /*  524288 */
+#define LDAP_DEBUG_NUNCSTANS  0x100000  /* 1048576 */
 
-#define LDAP_DEBUG_ALL_LEVELS	0xFFFFF
+#define LDAP_DEBUG_ALL_LEVELS	0xFFFFFF
 
 /* debugging stuff */
 /* Disable by default */

+ 22 - 0
ldap/servers/slapd/daemon.c

@@ -1232,6 +1232,27 @@ ns_enable_listeners()
 #endif
 }
 
+#ifdef ENABLE_NUNC_STANS
+/*
+ * Nunc stans logging function.
+ */
+static void
+nunc_stans_logging(int priority, const char *format, va_list varg)
+{
+	va_list varg_copy;
+	int severity = SLAPI_LOG_FATAL;
+
+	if (priority == LOG_DEBUG){
+		severity = SLAPI_LOG_NUNCSTANS;
+	} else if(priority == LOG_INFO){
+		severity = SLAPI_LOG_CONNS;
+	}
+	va_copy(varg_copy, varg);
+	slapi_log_error_ext(severity, "nunc-stans", (char *)format, varg, varg_copy);
+	va_end(varg_copy);
+}
+#endif
+
 void slapd_daemon( daemon_ports_t *ports )
 {
 	/* We are passed some ports---one for regular connections, one
@@ -1458,6 +1479,7 @@ void slapd_daemon( daemon_ports_t *ports )
 		tp_config.stacksize = 0;
 		tp_config.event_queue_size = config_get_maxdescriptors();
 		tp_config.work_queue_size = config_get_maxdescriptors();
+		tp_config.log_fct = nunc_stans_logging;
 
 		tp = ns_thrpool_new(&tp_config);
 		ns_add_signal_job(tp, SIGINT, NS_JOB_SIGNAL, ns_set_shutdown, NULL, NULL);

+ 3 - 2
ldap/servers/slapd/log.c

@@ -103,11 +103,12 @@ static int slapi_log_map[] = {
     LDAP_DEBUG_PLUGIN,		/* SLAPI_LOG_PLUGIN */
     LDAP_DEBUG_TIMING,		/* SLAPI_LOG_TIMING */
     LDAP_DEBUG_BACKLDBM,	/* SLAPI_LOG_BACKLDBM */
-    LDAP_DEBUG_ACLSUMMARY	/* SLAPI_LOG_ACLSUMMARY */
+    LDAP_DEBUG_ACLSUMMARY,	/* SLAPI_LOG_ACLSUMMARY */
+    LDAP_DEBUG_NUNCSTANS	/* SLAPI_LOG_NUNCSTANS */
 };
 
 #define SLAPI_LOG_MIN	SLAPI_LOG_FATAL		/* from slapi-plugin.h */
-#define SLAPI_LOG_MAX	SLAPI_LOG_ACLSUMMARY	/* from slapi-plugin.h */
+#define SLAPI_LOG_MAX	SLAPI_LOG_NUNCSTANS	/* from slapi-plugin.h */
 #define	TBUFSIZE 50				/* size for time buffers */
 #define SLAPI_LOG_BUFSIZ 2048			/* size for data buffers */
 /**************************************************************************

+ 2 - 1
ldap/servers/slapd/slapi-plugin.h

@@ -6096,7 +6096,8 @@ int slapi_log_error_ext( int severity, char *subsystem, char *fmt, va_list varg1
 #define SLAPI_LOG_PLUGIN		14
 #define SLAPI_LOG_TIMING		15
 #define SLAPI_LOG_BACKLDBM		16
-#define SLAPI_LOG_ACLSUMMARY		17 /* ACLSUMMARY must be the last (log.c) */
+#define SLAPI_LOG_ACLSUMMARY		17
+#define SLAPI_LOG_NUNCSTANS		18 /* The last level must be set in log.c: SLAPI_LOG_MAX */
 
 int slapi_is_loglevel_set( const int loglevel );