Added the vLog() function as a catch-all for logging.
authorcrh <crh@ubiqx.org>
Wed, 20 Jun 2012 16:57:31 +0000 (11:57 -0500)
committercrh <crh@ubiqx.org>
Wed, 20 Jun 2012 16:57:31 +0000 (11:57 -0500)
 * Adding vLog() made it easy to create the LockLog() function t PrequelD.c.  Originally, LockLog() was a macro, but there were problems using it as such.
 * Rewrote Log() and LogX() to use vLog(); removed some redundancy in the code.

src/daemon/PD_utils.c
src/daemon/PD_utils.h

index c7b55f2e40715ce821ee257170b96d6582326eda..69bbeb4c66e513ca5a4d5fc698bd125dda9d6025 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Email: crh@ubiqx.mn.org
  *
- * $Id: PD_utils.c 2012-06-12 21:44:48 -0500 crh$
+ * $Id: PD_utils.c 2012-06-20 11:57:31 -0500 crh$
  *
  * -------------------------------------------------------------------------- **
  *
@@ -168,12 +168,12 @@ bool setLogTimeStamp( bool tsState )
   } /* setLogTimeStamp */
 
 
-void Log( char *fmt, ... )
+void vLog( char *fmt, va_list ap )
   /* ------------------------------------------------------------------------ **
-   * Send a log message to the log file.
+   * Send a message to the log file.
    *
    *  Input:  fmt - Format string, as used in printf(), etc.
-   *          ... - Variable parameter list.
+   *          ap  - Variable parameter list.
    *
    *  Output: <none>
    *
@@ -188,12 +188,13 @@ void Log( char *fmt, ... )
    *          from multiple other modules.  It's not just used by the main
    *          program.
    *
+   *          This function serves the same purpose as <Log()>, below, except
+   *          that it is called with a va_list instead of a variable number
+   *          of arguments.
+   *
    * ------------------------------------------------------------------------ **
    */
   {
-  va_list ap;
-
-  va_start( ap, fmt );
   if( NULL == LogF )
     vsyslog( LOG_NOTICE, fmt, ap );
   else
@@ -202,6 +203,38 @@ void Log( char *fmt, ... )
       (void)fprintf( LogF, "%s ", timestamp() );
     (void)vfprintf( LogF, fmt, ap );
     }
+  } /* vLog */
+
+
+void Log( char *fmt, ... )
+  /* ------------------------------------------------------------------------ **
+   * Send a log message to the log file.
+   *
+   *  Input:  fmt - Format string, as used in printf(), etc.
+   *          ... - Variable parameter list.
+   *
+   *  Output: <none>
+   *
+   *  Notes:  When logging to syslog, all messages are written with priority
+   *          level LOG_NOTICE.
+   *
+   *          Each call to syslog() (or vsyslog()) generates a new log
+   *          message, so we cannot compose compound messages by calling
+   *          this function multiple times.  Compose first, call once.
+   *
+   *          This function is in the PD_utils module because it is called
+   *          from multiple other modules.  It's not just used by the main
+   *          program.
+   *
+   *  See Also: <vLog()>
+   *
+   * ------------------------------------------------------------------------ **
+   */
+  {
+  va_list ap;
+
+  va_start( ap, fmt );
+  vLog( fmt, ap );
   va_end( ap );
   } /* Log */
 
@@ -219,20 +252,15 @@ void LogX( int status, char *fmt, ... )
    *  Notes:  This is almost identical to <Log()> except that it calls
    *          exit(3), passing the value of <status>.
    *
+   *  See Also: <vLog()>
+   *
    * ------------------------------------------------------------------------ **
    */
   {
   va_list ap;
 
   va_start( ap, fmt );
-  if( NULL == LogF )
-    vsyslog( LOG_NOTICE, fmt, ap );
-  else
-    {
-    if( tStamp )
-      (void)fprintf( LogF, "%s ", timestamp() );
-    (void)vfprintf( LogF, fmt, ap );
-    }
+  vLog( fmt, ap );
   va_end( ap );
 
   exit( status );
index b94fa213b424a0dd44999a6e1baa22754f5cef0a..7c7649f2ab17911650cca7e0d87ff5ac4ae711ba 100644 (file)
@@ -8,7 +8,7 @@
  *
  * Email: crh@ubiqx.mn.org
  *
- * $Id: PD_utils.h 2012-06-12 21:44:48 -0500 crh$
+ * $Id: PD_utils.h 2012-06-20 11:57:31 -0500 crh$
  *
  * -------------------------------------------------------------------------- **
  *
@@ -133,6 +133,34 @@ bool setLogTimeStamp( bool tsState );
    */
 
 
+void vLog( char *fmt, va_list ap );
+  /* ------------------------------------------------------------------------ **
+   * Send a message to the log file.
+   *
+   *  Input:  fmt - Format string, as used in printf(), etc.
+   *          ap  - Variable parameter list.
+   *
+   *  Output: <none>
+   *
+   *  Notes:  When logging to syslog, all messages are written with priority
+   *          level LOG_NOTICE.
+   *
+   *          Each call to syslog() (or vsyslog()) generates a new log
+   *          message, so we cannot compose compound messages by calling
+   *          this function multiple times.  Compose first, call once.
+   *
+   *          This function is in the PD_utils module because it is called
+   *          from multiple other modules.  It's not just used by the main
+   *          program.
+   *
+   *          This function serves the same purpose as <Log()>, below, except
+   *          that it is called with a va_list instead of a variable number
+   *          of arguments.
+   *
+   * ------------------------------------------------------------------------ **
+   */
+
+
 void Log( char *fmt, ... );
   /* ------------------------------------------------------------------------ **
    * Send a log message to the log file.
@@ -153,6 +181,8 @@ void Log( char *fmt, ... );
    *          from multiple other modules.  It's not just used by the main
    *          program.
    *
+   *  See Also: <vLog()>
+   *
    * ------------------------------------------------------------------------ **
    */
 
@@ -170,6 +200,8 @@ void LogX( int status, char *fmt, ... );
    *  Notes:  This is almost identical to <Log()> except that it calls
    *          exit(3), passing the value of <status>.
    *
+   *  See Also: <vLog()>
+   *
    * ------------------------------------------------------------------------ **
    */