[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r8534: Omit function names from NOTICE, WARN and ERR messages unles (in tor/trunk: . src/common)



Author: nickm
Date: 2006-09-29 14:13:29 -0400 (Fri, 29 Sep 2006)
New Revision: 8534

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/common/log.c
Log:
 r9006@Kushana:  nickm | 2006-09-29 10:48:23 -0400
 Omit function names from NOTICE, WARN and ERR messages unless they are in LD_BUG.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r9006] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2006-09-29 18:13:25 UTC (rev 8533)
+++ tor/trunk/ChangeLog	2006-09-29 18:13:29 UTC (rev 8534)
@@ -42,6 +42,9 @@
       any router is the canonical Unnamed.
     - New controller event to alert the controller when our server descriptor
       has changed.
+    - Only include function names in log messages for debugging messages;
+      in other cases, the content of the message should be clear on its own,
+      and including the function name only seems to confuse users.
 
   o Security Fixes, minor:
     - If a client asked for a server by name, and we didn't have a

Modified: tor/trunk/src/common/log.c
===================================================================
--- tor/trunk/src/common/log.c	2006-09-29 18:13:25 UTC (rev 8533)
+++ tor/trunk/src/common/log.c	2006-09-29 18:13:29 UTC (rev 8534)
@@ -60,6 +60,26 @@
   }
 }
 
+/** Helper: decide whether to include the function name in the log message.
+ * */
+static INLINE int
+should_log_function_name(uint32_t domain, int severity)
+{
+  switch (severity) {
+    case LOG_DEBUG:
+    case LOG_INFO:
+      /* All debugging messages occur in interesting places. */
+      return 1;
+    case LOG_NOTICE:
+    case LOG_WARN:
+    case LOG_ERR:
+      /* We care about places where bugs occur. */
+      return (domain == LD_BUG);
+    default:
+      assert(0); return 0;
+  }
+}
+
 /** Linked list of logfile_t. */
 static logfile_t *logfiles = NULL;
 #ifdef HAVE_SYSLOG_H
@@ -137,7 +157,7 @@
  */
 static INLINE char *
 format_msg(char *buf, size_t buf_len,
-           int severity, const char *funcname,
+           uint32_t domain, int severity, const char *funcname,
            const char *format, va_list ap)
 {
   size_t n;
@@ -150,7 +170,7 @@
   n = _log_prefix(buf, buf_len, severity);
   end_of_prefix = buf+n;
 
-  if (funcname) {
+  if (funcname && should_log_function_name(domain, severity)) {
     r = tor_snprintf(buf+n, buf_len-n, "%s(): ", funcname);
     if (r<0)
       n = strlen(buf);
@@ -206,7 +226,7 @@
 
     if (!formatted) {
       end_of_prefix =
-        format_msg(buf, sizeof(buf), severity, funcname, format, ap);
+        format_msg(buf, sizeof(buf), domain, severity, funcname, format, ap);
       formatted = 1;
     }
     if (lf->is_syslog) {