]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/log.c
Fix t_diff(): declaration of 'div' shadows a global declaration
[ngircd-alex.git] / src / ngircd / log.c
index 459ba1d296da77d5addfe58e93d7e0153e52a518..9c4daf557f8239bd0c6307aef02a23ad4ee0208d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: log.c,v 1.57 2005/06/24 19:55:10 alex Exp $";
+static char UNUSED id[] = "$Id: log.c,v 1.62 2006/08/05 09:16:21 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -44,15 +44,15 @@ static char UNUSED id[] = "$Id: log.c,v 1.57 2005/06/24 19:55:10 alex Exp $";
 #include "log.h"
 
 
-LOCAL char Init_Txt[127];
-LOCAL bool Is_Daemon;
+static char Init_Txt[127];
+static bool Is_Daemon;
 
 #ifdef DEBUG
-LOCAL char Error_File[FNAME_LEN];
+static char Error_File[FNAME_LEN];
 #endif
 
 
-LOCAL void Wall_ServerNotice PARAMS(( char *Msg ));
+static void Wall_ServerNotice PARAMS(( char *Msg ));
 
 
 GLOBAL void
@@ -162,6 +162,51 @@ Log_Exit( void )
 } /* Log_Exit */
 
 
+/**
+ * Log function for debug messages.
+ * This function is only functional when the program is compiled with debug
+ * code enabled; otherwise it is an empty function which the compiler will
+ * hopefully mangle down to "nothing" (see log.h). Therefore you should use
+ * LogDebug(...) in favor to Log(LOG_DEBUG, ...).
+ * @param Format Format string like printf().
+ * @param ... Further arguments.
+ */
+#ifdef DEBUG
+# ifdef PROTOTYPES
+GLOBAL void
+LogDebug( const char *Format, ... )
+# else
+GLOBAL void
+LogDebug( Format, va_alist )
+const char *Format;
+va_dcl
+# endif /* PROTOTYPES */
+{
+       char msg[MAX_LOG_MSG_LEN];
+       va_list ap;
+
+       if (!NGIRCd_Debug) return;
+#ifdef PROTOTYPES
+       va_start( ap, Format );
+#else
+       va_start( ap );
+#endif
+       vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
+       va_end( ap );
+       Log(LOG_DEBUG, "%s", msg);
+}
+#endif /* DEBUG */
+
+
+/**
+ * Logging function of ngIRCd.
+ * This function logs messages to the console and/or syslog, whichever is
+ * suitable for the mode ngIRCd is running in (daemon vs. non-daemon).
+ * Please note: you sould use LogDebug(...) for debug messages!
+ * @param Level syslog level (LOG_xxx)
+ * @param Format Format string like printf().
+ * @param ... Further arguments.
+ */
 #ifdef PROTOTYPES
 GLOBAL void
 Log( int Level, const char *Format, ... )
@@ -174,7 +219,6 @@ va_dcl
 #endif
 {
        /* Eintrag in Logfile(s) schreiben */
-
        char msg[MAX_LOG_MSG_LEN];
        bool snotice;
        va_list ap;
@@ -302,19 +346,23 @@ va_dcl
 } /* Log_Resolver */
 
 
-LOCAL void
+/**
+ * Send log messages to users flagged with the "s" mode.
+ * @param Msg The message to send.
+ */
+static void
 Wall_ServerNotice( char *Msg )
 {
-       /* Server-Notice an entsprechende User verschicken */
-
        CLIENT *c;
 
        assert( Msg != NULL );
 
        c = Client_First( );
-       while( c )
-       {
-               if(( Client_Conn( c ) > NONE ) && ( Client_HasMode( c, 's' ))) IRC_WriteStrClient( c, "NOTICE %s :%s%s", Client_ThisServer( ), NOTICE_TXTPREFIX, Msg );
+       while(c) {
+               if (Client_Conn(c) > NONE && Client_HasMode(c, 's'))
+                       IRC_WriteStrClient(c, "NOTICE %s :%s%s", Client_ID(c),
+                                                       NOTICE_TXTPREFIX, Msg);
+
                c = Client_Next( c );
        }
 } /* Wall_ServerNotice */