commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/geas/src/datamonitor datamonitor.c datamon...


From: Reinhard Mueller
Subject: gnue/geas/src/datamonitor datamonitor.c datamon...
Date: Mon, 28 May 2001 15:51:22 -0700

CVSROOT:        /cvs
Module name:    gnue
Changes by:     Reinhard Mueller <address@hidden>       01/05/28 15:51:22

Modified files:
        geas/src/datamonitor: datamonitor.c datamonitor.h 

Log message:
        reformatted

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/datamonitor/datamonitor.c.diff?cvsroot=OldCVS&tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/datamonitor/datamonitor.h.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: gnue/geas/src/datamonitor/datamonitor.c
diff -u gnue/geas/src/datamonitor/datamonitor.c:1.7 
gnue/geas/src/datamonitor/datamonitor.c:1.8
--- gnue/geas/src/datamonitor/datamonitor.c:1.7 Fri May 25 08:46:50 2001
+++ gnue/geas/src/datamonitor/datamonitor.c     Mon May 28 15:51:22 2001
@@ -1,380 +1,426 @@
-/* 
-   geas - GNU Enterprise Application Server
+/*
+   Database communication monitoring
 
    Copyright (C) 2001 Free Software Foundation
 
-   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
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   This file is part of the GNU Enterprise Application Server (GEAS)
 
+   GEAS is free software; you can redistribute it and/or modify it under
+   the terms of the GNU General Public License as published by the Free
+   Software Foundation; either version 2, or (at your option) any later
+   version.
+
+   GEAS is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   for more details.
+
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+   along with GEAS; if not, write to the Free Software Foundation, Inc.,
+   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+   $Id: datamonitor.c,v 1.8 2001/05/28 22:51:22 reinhard Exp $
 */
 
 #include "config.h"
-
-#include <glib.h>
+#include "datamonitor.h"
 #include <stdio.h>
 #include <time.h>
 #include <unistd.h>
 #include <sys/times.h>
-
-#include "datamonitor.h"
+#include <glib.h>
 
-struct dm_logfile
+/* ========================================================================= *\
+ * Private structures
+\* ========================================================================= */
+
+/* ------------------------------------------------------------------------- *\
+ * Name of the logfile and wich events to log into this file
+\* ------------------------------------------------------------------------- */
+struct _dm_logfile
 {
-   char *name;
-   unsigned long int events;
-   unsigned long int flags;
+  gchar *name;
+  guint32 events;
+  guint32 flags;
 };
 
+typedef struct _dm_logfile dm_logfile;
+
+/* ========================================================================= *\
+ * Global variables
+\* ========================================================================= */
+
 static gboolean datamonitor_open = FALSE;
 static GList *datamonitor_logfiles = NULL;
 
-void init_datamonitor()
+/* ========================================================================= *\
+ * Private functions
+\* ========================================================================= */
+
+/* ------------------------------------------------------------------------- *\
+ * Return the name of the event
+\* ------------------------------------------------------------------------- */
+static const gchar *
+_dm_get_event_name (guint32 event)
 {
-   datamonitor_logfiles = NULL;
-   datamonitor_open = TRUE;
+  if (event == DM_EVENT_OBJECT_NEW)             return "new";
+  if (event == DM_EVENT_OBJECT_DELETE)          return "delete";
+  if (event == DM_EVENT_FIELD_WRITE)            return "write";
+  if (event == DM_EVENT_FIELD_READ)             return "read";
+
+  if (event == DM_TRANSACTION_ROLLBACK)         return "rollback";
+  if (event == DM_TRANSACTION_COMMIT)           return "commit";
+  if (event == DM_TRANSACTION_BEGIN)            return "begin";
+  if (event == DM_TRANSACTION_CHECKPOINT)       return "checkpoint";
+
+  if (event == DM_EVENT_SECURITY_LOGON_SUCCESS) return "login_success";
+  if (event == DM_EVENT_SECURITY_LOGON_FAIL)    return "login_fail";
+  if (event == DM_EVENT_SECURITY)               return "security";
+
+  if (event == DM_EVENT_ERROR)                  return "error";
+  if (event == DM_EVENT_WARNING)                return "warning";
+  if (event == DM_EVENT_MESSAGE)                return "message";
+
+  if (event == DM_EVENT_DATABASE)               return "database";
+
+  return "unknown event";
 }
 
-void close_datamonitor()
+/* ------------------------------------------------------------------------- *\
+ * Write the first part of a line of the logfile
+\* ------------------------------------------------------------------------- */
+static void
+_dm_write_logline_start (FILE * fp, const gchar *username,
+                        const gchar *transactionid, guint32 event)
 {
-   GList *l;
-   datamonitor_open = FALSE;
-
-   if( datamonitor_logfiles )
-     {
-       l = datamonitor_logfiles;
-       while( l )
-         {
-            if( l->data )
-              {
-                 g_free( ((struct dm_logfile *)l->data)->name );
-                 g_free( l->data );
-              }
-            l = g_list_next( l );
-         }
-       g_list_free( datamonitor_logfiles );
-       datamonitor_logfiles = NULL;
-     }
+  /* 'theclock' was going to be a microsecond accurate timer, but that    */
+  /* didn't work well. instead, it is incremented each time this function */
+  /* is called, wrapping after 4294967295 */
+  /* the result is every log entry has a gruanteeed unique first 38 */
+  /* characters, and can always be sorted accurately, even when multiple */
+  /* entries are made in the same second (time() is limited to 1 sec     */
+  /* accuracy */
+  /* char *timestr; */
+  char timestr[32];
+  /* clock_t ticker = clock(); */
+  static unsigned long int ticker = 0;
+  time_t thetime = time (NULL);
+  struct tm *tm;
+  static int last_sec = 0;
+
+  /* print time, including microseconds */
+  /* timestr = g_strdup( ctime(&thetime) ); */
+  /* YYYY-MM-DD HH:MM:SS xxxxxxxx */
+  tm = localtime (&thetime);
+  strftime (timestr, 32, "%Y-%m-%d %H:%M:%S", tm);
+
+  /* for each entry that occurs in the same second, increment the
+     ticker. when we reach a later second, reset to 0.
+     Even if the first call is in second 0 of the minute,
+     the ticker is statically initialised, so will be usable
+     this ensures every call can have a unique ticker value,
+     provided this function is made thread safe - TODO */
+  if (last_sec == tm->tm_sec)
+    ticker++;
+  else
+    ticker = 1;
+  last_sec = tm->tm_sec;
+
+  /* [ time event user transaction ] extra info */
+  while (timestr[strlen (timestr) - 1] == '\n' ||
+         timestr[strlen (timestr) - 1] == 13 ||
+         timestr[strlen (timestr) - 1] == 10)
+    timestr[strlen (timestr) - 1] = '\0';
+  /* fprintf(fp, "[%s %010lu e:" , timestr , ticker ); */
+  fprintf (fp, "[%s %08lu e:", timestr, ticker);
+  /* g_free( timestr ); */
+
+  fprintf (fp, " %s", _dm_get_event_name (event));
+  if (username)
+    fprintf (fp, " u:%s", username);
+  else
+    fprintf (fp, " u:<server>");
+  if (transactionid)
+    fprintf (fp, " t:%s", transactionid);
+  fprintf (fp, "] ");
 }
 
-void add_datamonitor_logfile( const char *logfile , 
-                             unsigned long int events ,
-                             unsigned long int flags )
+/* ========================================================================= *\
+ * Public functions
+\* ========================================================================= */
+
+/* ------------------------------------------------------------------------- *\
+ * Initialize datamonitor - to be called at the start of a program
+\* ------------------------------------------------------------------------- */
+void
+init_datamonitor ()
 {
-   struct dm_logfile *l = g_new0( struct dm_logfile , 1 );
-   if( l )
-     {
-       l->name = g_strdup( logfile );
-       l->events = events;
-       l->flags = flags;
-
-       if( !l->name )
-         {
-            g_free( l );
-         }
-       else
-         {
-            datamonitor_logfiles =
-              g_list_append(datamonitor_logfiles , l );
-         }
-     }
+  datamonitor_logfiles = NULL;
+  datamonitor_open = TRUE;
 }
 
-static void
-dm_print_event_name( FILE *fp , unsigned long int event )
+/* ------------------------------------------------------------------------- *\
+ * Shut down datamonitor - to be called at the end of a program
+\* ------------------------------------------------------------------------- */
+void
+close_datamonitor ()
 {
-   if( event == DM_EVENT_OBJECT_NEW )    fprintf( fp , " new" );
-   if( event == DM_EVENT_OBJECT_DELETE ) fprintf( fp , " delete" );
-   if( event == DM_EVENT_FIELD_WRITE )   fprintf( fp , " write" );
-   if( event == DM_EVENT_FIELD_READ )    fprintf( fp , " read" );
-
-   if( event == DM_TRANSACTION_ROLLBACK   )    fprintf( fp , " rollback"   );
-   if( event == DM_TRANSACTION_COMMIT     )    fprintf( fp , " commit"     );
-   if( event == DM_TRANSACTION_BEGIN      )    fprintf( fp , " begin"      );
-   if( event == DM_TRANSACTION_CHECKPOINT )    fprintf( fp , " checkpoint" );
-
-   if( event == DM_EVENT_SECURITY_LOGON_SUCCESS ) fprintf( fp , " 
login_success" );
-   if( event == DM_EVENT_SECURITY_LOGON_FAIL )    fprintf( fp , " login_fail" 
);
-   if( event == DM_EVENT_SECURITY )               fprintf( fp , " security" );
-
-   if( event == DM_EVENT_ERROR   )     fprintf( fp , " error" );
-   if( event == DM_EVENT_WARNING )     fprintf( fp , " warning" );
-   if( event == DM_EVENT_MESSAGE )     fprintf( fp , " message" );
+  GList *l;
 
-   if( event == DM_EVENT_DATABASE)     fprintf( fp , " database" );
+  datamonitor_open = FALSE;
+
+  if (datamonitor_logfiles)
+    {
+      l = datamonitor_logfiles;
+      while (l)
+        {
+          if (l->data)
+            {
+              g_free (((dm_logfile *) l->data)->name);
+              g_free (l->data);
+            }
+          l = g_list_next (l);
+        }
+      g_list_free (datamonitor_logfiles);
+      datamonitor_logfiles = NULL;
+    }
 }
 
-static void
-dm_write_logline_start( FILE *fp , const char *username ,
-                       const char *transactionid , unsigned long int event )
+/* ------------------------------------------------------------------------- *\
+ * Add a file to the list of active logfiles
+\* ------------------------------------------------------------------------- */
+void
+add_datamonitor_logfile (const gchar *logfile, guint32 events, guint32 flags)
 {
-   /* 'theclock' was going to be a microsecond accurate timer, but that    */
-   /* didn't work well. instead, it is incremented each time this function */
-   /* is called, wrapping after 4294967295 */
-   /* the result is every log entry has a gruanteeed unique first 38 */
-   /* characters, and can always be sorted accurately, even when multiple */
-   /* entries are made in the same second (time() is limited to 1 sec     */
-   /* accuracy */
-   /* char *timestr; */
-   char timestr[32];
-   /* clock_t ticker = clock(); */
-   static unsigned long int ticker = 0;
-   time_t  thetime = time(NULL);
-   struct tm *tm;
-   static int last_sec = 0;
-
-   /* print time, including microseconds */
-   /* timestr = g_strdup( ctime(&thetime) ); */
-   /* YYYY-MM-DD HH:MM:SS xxxxxxxx */
-   tm = localtime(&thetime);
-   strftime(timestr,32,"%Y-%m-%d %H:%M:%S",tm);
-
-   /* for each entry that occurs in the same second, increment the
-      ticker. when we reach a later second, reset to 0.
-      Even if the first call is in second 0 of the minute,
-      the ticker is statically initialised, so will be usable
-      this ensures every call can have a unique ticker value,
-      provided this function is made thread safe - TODO */
-   if( last_sec == tm->tm_sec )
-     ticker++;
-   else
-     ticker = 1;
-   last_sec = tm->tm_sec;
-
-   /* [ time event user transaction ] extra info */
-   while( timestr[strlen(timestr)-1] == '\n' ||
-        timestr[strlen(timestr)-1] == 13   ||
-        timestr[strlen(timestr)-1] == 10 )
-     timestr[strlen(timestr)-1] = '\0';
-   /* fprintf(fp, "[%s %010lu e:" , timestr , ticker ); */
-   fprintf(fp, "[%s %08lu e:" , timestr , ticker );
-   /* g_free( timestr ); */
-
-   dm_print_event_name( fp , event );
-   if( username )
-     fprintf(fp , " u:%s" , username );
-   else
-     fprintf(fp , " u:<server>" );
-   if( transactionid )
-     fprintf( fp , " t:%s" , transactionid );
-   fprintf(fp , "] " );
+  dm_logfile *l;
+
+  g_return_if_fail (logfile);
+
+  l = g_new0 (dm_logfile, 1);
+
+  l->name = g_strdup (logfile);
+  l->events = events;
+  l->flags = flags;
+
+  datamonitor_logfiles = g_list_append (datamonitor_logfiles, l);
 }
 
-void dm_event( const char *username , const char *transactionid ,
-              unsigned long int event , ... )
+/* ------------------------------------------------------------------------- *\
+ * Log a predefined event
+\* ------------------------------------------------------------------------- */
+void
+dm_event (const gchar *username, const gchar *transactionid, guint32 event,
+          ...)
 {
-   GList *l = datamonitor_logfiles;
-   gboolean write;
-   struct dm_logfile *lf;
-
-   /* write event to log files */
-   while( l )
-     {
-       lf = (struct dm_logfile *)l->data;
-       /* printf( "Checking file %s\n" , lf->name ); */
-       write = FALSE;
-       /* printf( "[%d %d %d] " , lf->events , event , lf->events & event ); */
-       if( (lf->events & event) == event )
-         {
-            write = TRUE;
-            if( transactionid )
-              {
-                 /* transaction, only write if allowed */
-                 /* printf( "   %d %d " , lf->flags , lf->flags & 
DM_LOG_ALLOW_TRANSACTIONS ); */
-                 if( (lf->flags & DM_LOG_ALLOW_TRANSACTIONS) == 0 ) {
-                    write = FALSE;
-                    /* printf( "transaction not allowed\n" ); */
-                 }
-              }
-            else
-              {
-                 /* no transaction: if required then don't write */
-                 /* printf( "   %d %d " , lf->flags , lf->flags & 
DM_LOG_REQUIRE_TRANSACTIONS ); */
-                 if( (lf->flags & DM_LOG_REQUIRE_TRANSACTIONS) == 
DM_LOG_REQUIRE_TRANSACTIONS ) {
-                    write = FALSE;
-                    /* printf( "transaction required\n" ); */
-                 }
-              }
-         }
-       else {
-         /* printf( "event not logged\n" ); */
-         write = FALSE;
-       }
-
-       if( write )
-         {
-            FILE *fp = fopen( lf->name , "a" );
-            if( fp )
-              {
-                 va_list a;
-
-                 /* printf( "  event logged\n" ); */
-                 dm_write_logline_start( fp , username ,
-                       transactionid , event );
-
-                 /* display event details */
-                 switch( event )
-                   {
-                    case DM_EVENT_OBJECT_NEW:
-                      /* classname/object id */
-                      va_start(a,event);
-                      vfprintf( fp , "%s/%s" , a );
-                      va_end( a );
-                      break;
-                    case DM_EVENT_OBJECT_DELETE:
-                      /* classname/objectid */
-                      va_start(a,event);
-                      vfprintf( fp , "%s/%s" , a );
-                      va_end( a );
-                      break;
-                    case DM_EVENT_FIELD_WRITE:
-                      /* classname/objectid.field = value */
-                      va_start(a,event);
-                      vfprintf( fp , "%s/%s.%s = %s" , a );
-                      va_end( a );
-                      break;
-                    case DM_EVENT_FIELD_READ:
-                      /* classname/objectid.fieldname */
-                      va_start(a,event);
-                      vfprintf( fp , "%s/%s.%s" , a );
-                      va_end( a );
-                      break;
-                    case DM_TRANSACTION_BEGIN:
-                    case DM_TRANSACTION_COMMIT:
-                    case DM_TRANSACTION_ROLLBACK:
-                    case DM_TRANSACTION_CHECKPOINT:
-                      /* no extra info for transaction events */
-                      break;
-                   }
-                 fprintf( fp , "\n" );
-
-                 /* done */
-                 fclose( fp );
-              }
-         }
-       l = g_list_next( l );
-     }
-   /* printf( "\n" ); */
-
-
-   /* handle an event */
-
-   /* abort data monitor if not initialised */
-   if( !datamonitor_open )
-       return;
+  GList *l = datamonitor_logfiles;
+  gboolean write;
+  dm_logfile *lf;
+
+  /* write event to log files */
+  while (l)
+    {
+      lf = (dm_logfile *) l->data;
+      /* printf( "Checking file %s\n" , lf->name ); */
+      write = FALSE;
+      /* printf( "[%d %d %d] " , lf->events , event , lf->events & event ); */
+      if ((lf->events & event) == event)
+        {
+          write = TRUE;
+          if (transactionid)
+            {
+              /* transaction, only write if allowed */
+              /* printf( "   %d %d " , lf->flags , lf->flags & 
DM_LOG_ALLOW_TRANSACTIONS ); */
+              if ((lf->flags & DM_LOG_ALLOW_TRANSACTIONS) == 0)
+                {
+                  write = FALSE;
+                  /* printf( "transaction not allowed\n" ); */
+                }
+            }
+          else
+            {
+              /* no transaction: if required then don't write */
+              /* printf( "   %d %d " , lf->flags , lf->flags & 
DM_LOG_REQUIRE_TRANSACTIONS ); */
+              if ((lf->flags & DM_LOG_REQUIRE_TRANSACTIONS) ==
+                  DM_LOG_REQUIRE_TRANSACTIONS)
+                {
+                  write = FALSE;
+                  /* printf( "transaction required\n" ); */
+                }
+            }
+        }
+      else
+        {
+          /* printf( "event not logged\n" ); */
+          write = FALSE;
+        }
+
+      if (write)
+        {
+          FILE *fp = fopen (lf->name, "a");
+          if (fp)
+            {
+              va_list a;
+
+              /* printf( "  event logged\n" ); */
+              _dm_write_logline_start (fp, username, transactionid, event);
+
+              /* display event details */
+              switch (event)
+                {
+                case DM_EVENT_OBJECT_NEW:
+                  /* classname/object id */
+                  va_start (a, event);
+                  vfprintf (fp, "%s/%s", a);
+                  va_end (a);
+                  break;
+                case DM_EVENT_OBJECT_DELETE:
+                  /* classname/objectid */
+                  va_start (a, event);
+                  vfprintf (fp, "%s/%s", a);
+                  va_end (a);
+                  break;
+                case DM_EVENT_FIELD_WRITE:
+                  /* classname/objectid.field = value */
+                  va_start (a, event);
+                  vfprintf (fp, "%s/%s.%s = %s", a);
+                  va_end (a);
+                  break;
+                case DM_EVENT_FIELD_READ:
+                  /* classname/objectid.fieldname */
+                  va_start (a, event);
+                  vfprintf (fp, "%s/%s.%s", a);
+                  va_end (a);
+                  break;
+                case DM_TRANSACTION_BEGIN:
+                case DM_TRANSACTION_COMMIT:
+                case DM_TRANSACTION_ROLLBACK:
+                case DM_TRANSACTION_CHECKPOINT:
+                  /* no extra info for transaction events */
+                  break;
+                }
+              fprintf (fp, "\n");
+
+              /* done */
+              fclose (fp);
+            }
+        }
+      l = g_list_next (l);
+    }
+  /* printf( "\n" ); */
+
+
+  /* handle an event */
+
+  /* abort data monitor if not initialised */
+  if (!datamonitor_open)
+    return;
 
-   /* code here should be able to track data requests, and optimise */
-   /* the data cache and other systems */
+  /* code here should be able to track data requests, and optimise */
+  /* the data cache and other systems */
 }
 
-/* log generic events (ie, anything except data operations) */
+/* ------------------------------------------------------------------------- *\
+ * Log anything except a predefined event
+\* ------------------------------------------------------------------------- */
 void
-dm_logentry( unsigned long int type , const char *username , const char *fmt , 
... )
+dm_logentry (guint32 type, const gchar *username, const gchar *fmt, ...)
 {
-   GList *l = datamonitor_logfiles;
-   gboolean write;
-   struct dm_logfile *lf;
-
-   /* write event to log files */
-   while( l )
-     {
-       lf = (struct dm_logfile *)l->data;
-       /* printf( "Checking file %s\n" , lf->name ); */
-       write = FALSE;
-       /* printf( "[%d %d %d] " , lf->events , event , lf->events & event ); */
-       if( (lf->events & type) == type )
-         {
-            write = TRUE;
-         }
-       else {
-         /* printf( "event not logged\n" ); */
-         write = FALSE;
-       }
-
-       if( write )
-         {
-            FILE *fp = fopen( lf->name , "a" );
-            if( fp )
-              {
-                 va_list a;
-
-                 /* printf( "  event logged\n" ); */
-                 dm_write_logline_start( fp , username ,
-                       NULL , type );
-
-                 /* display event details */
-                 if( fmt )
-                   {
-                      va_start(a,fmt);
-                      vfprintf( fp , fmt , a );
-                      va_end( a );
-                   }
-                 fprintf( fp , "\n" );
-
-                 /* done */
-                 fclose( fp );
-              }
-         }
-       l = g_list_next( l );
-     }
-   /* printf( "\n" ); */
+  GList *l = datamonitor_logfiles;
+  gboolean write;
+  dm_logfile *lf;
+
+  /* write event to log files */
+  while (l)
+    {
+      lf = (dm_logfile *) l->data;
+      /* printf( "Checking file %s\n" , lf->name ); */
+      write = FALSE;
+      /* printf( "[%d %d %d] " , lf->events , event , lf->events & event ); */
+      if ((lf->events & type) == type)
+        {
+          write = TRUE;
+        }
+      else
+        {
+          /* printf( "event not logged\n" ); */
+          write = FALSE;
+        }
+
+      if (write)
+        {
+          FILE *fp = fopen (lf->name, "a");
+          if (fp)
+            {
+              va_list a;
+
+              /* printf( "  event logged\n" ); */
+              _dm_write_logline_start (fp, username, NULL, type);
+
+              /* display event details */
+              if (fmt)
+                {
+                  va_start (a, fmt);
+                  vfprintf (fp, fmt, a);
+                  va_end (a);
+                }
+              fprintf (fp, "\n");
+
+              /* done */
+              fclose (fp);
+            }
+        }
+      l = g_list_next (l);
+    }
+  /* printf( "\n" ); */
 }
 
+/* ------------------------------------------------------------------------- *\
+ * Same as dm_logentry, but with va_list parameter
+\* ------------------------------------------------------------------------- */
 void
-dm_vlogentry( unsigned long int type , const char *username , const char *fmt 
, va_list a )
+dm_vlogentry (guint32 type, const gchar *username, const gchar *fmt, va_list a)
 {
-   GList *l = datamonitor_logfiles;
-   gboolean write;
-   struct dm_logfile *lf;
-
-   /* write event to log files */
-   while( l )
-     {
-       lf = (struct dm_logfile *)l->data;
-       /* printf( "Checking file %s\n" , lf->name ); */
-       write = FALSE;
-       /* printf( "[%d %d %d] " , lf->events , event , lf->events & event ); */
-       if( (lf->events & type) == type )
-         {
-            write = TRUE;
-         }
-       else {
-         /* printf( "event not logged\n" ); */
-         write = FALSE;
-       }
-
-       if( write )
-         {
-            FILE *fp = fopen( lf->name , "a" );
-            if( fp )
-              {
-                 /* printf( "  event logged\n" ); */
-                 dm_write_logline_start( fp , username ,
-                       NULL , type );
-
-                 /* display event details */
-                 if( fmt )
-                   {
-                      vfprintf( fp , fmt , a );
-                   }
-                 fprintf( fp , "\n" );
-
-                 /* done */
-                 fclose( fp );
-              }
-         }
-       l = g_list_next( l );
-     }
-   /* printf( "\n" ); */
+  GList *l = datamonitor_logfiles;
+  gboolean write;
+  dm_logfile *lf;
+
+  /* write event to log files */
+  while (l)
+    {
+      lf = (dm_logfile *) l->data;
+      /* printf( "Checking file %s\n" , lf->name ); */
+      write = FALSE;
+      /* printf( "[%d %d %d] " , lf->events , event , lf->events & event ); */
+      if ((lf->events & type) == type)
+        {
+          write = TRUE;
+        }
+      else
+        {
+          /* printf( "event not logged\n" ); */
+          write = FALSE;
+        }
+
+      if (write)
+        {
+          FILE *fp = fopen (lf->name, "a");
+          if (fp)
+            {
+              /* printf( "  event logged\n" ); */
+              _dm_write_logline_start (fp, username, NULL, type);
+
+              /* display event details */
+              if (fmt)
+                {
+                  vfprintf (fp, fmt, a);
+                }
+              fprintf (fp, "\n");
+
+              /* done */
+              fclose (fp);
+            }
+        }
+      l = g_list_next (l);
+    }
+  /* printf( "\n" ); */
 }
-
Index: gnue/geas/src/datamonitor/datamonitor.h
diff -u gnue/geas/src/datamonitor/datamonitor.h:1.5 
gnue/geas/src/datamonitor/datamonitor.h:1.6
--- gnue/geas/src/datamonitor/datamonitor.h:1.5 Mon May 14 14:57:57 2001
+++ gnue/geas/src/datamonitor/datamonitor.h     Mon May 28 15:51:22 2001
@@ -1,22 +1,25 @@
-/* 
-   geas - GNU Enterprise Application Server
+/*
+   Database communication monitoring
 
    Copyright (C) 2001 Free Software Foundation
 
-   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
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   This file is part of the GNU Enterprise Application Server (GEAS)
 
+   GEAS is free software; you can redistribute it and/or modify it under
+   the terms of the GNU General Public License as published by the Free
+   Software Foundation; either version 2, or (at your option) any later
+   version.
+
+   GEAS is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   for more details.
+
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+   along with GEAS; if not, write to the Free Software Foundation, Inc.,
+   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+   $Id: datamonitor.h,v 1.6 2001/05/28 22:51:22 reinhard Exp $
 */
 
 #include <glib.h>
@@ -25,40 +28,40 @@
 #define DATAMONITOR_H
 
 /* log everything */
-#define DM_ALL                 0xffffffff
+#define DM_ALL                          0xffffffff
 
 /* write events */
-#define DM_EVENT_OBJECT_NEW          0x00000001 /* classname/objectid */
-#define DM_EVENT_OBJECT_DELETE       0x00000002 /* classname/objectid */
-#define DM_EVENT_FIELD_WRITE         0x00000004 /* classname/objectid.field = 
value */
+#define DM_EVENT_OBJECT_NEW             0x00000001 /* classname/objectid */
+#define DM_EVENT_OBJECT_DELETE          0x00000002 /* classname/objectid */
+#define DM_EVENT_FIELD_WRITE            0x00000004 /* classname/objectid.field 
= value */
 
 /* read events */
-#define DM_EVENT_FIELD_READ          0x00000008 /* classname/objectid.field */
+#define DM_EVENT_FIELD_READ             0x00000008 /* classname/objectid.field 
*/
 
 /* transaction events */
-#define DM_TRANSACTION_BEGIN         0x00000010
-#define DM_TRANSACTION_COMMIT        0x00000020
-#define DM_TRANSACTION_ROLLBACK      0x00000040
-#define DM_TRANSACTION_CHECKPOINT    0x00000080
+#define DM_TRANSACTION_BEGIN            0x00000010
+#define DM_TRANSACTION_COMMIT           0x00000020
+#define DM_TRANSACTION_ROLLBACK         0x00000040
+#define DM_TRANSACTION_CHECKPOINT       0x00000080
 
 /* log all events */
 #define DM_EVENT_ALL (DM_EVENT_OBJECT_NEW | DM_EVENT_OBJECT_DELETE | 
DM_EVENT_FIELD_WRITE | DM_EVENT_FIELD_READ)
 
 /* generic logable events */
-#define DM_EVENT_WARNING                  0x00000100
-#define DM_EVENT_ERROR                    0x00000200
-#define DM_EVENT_MESSAGE                  0x00000400
-#define DM_EVENT_DATABASE                 0x00000800
+#define DM_EVENT_WARNING                0x00000100
+#define DM_EVENT_ERROR                  0x00000200
+#define DM_EVENT_MESSAGE                0x00000400
+#define DM_EVENT_DATABASE               0x00000800
 
 /* log all generic messages */
 #define DM_MESSAGE_ALL (DM_EVENT_WARNING | DM_EVENT_ERROR | DM_EVENT_MESSAGE)
 
-#define DM_EVENT_SECURITY_LOGON_SUCCESS   0x01000000
-#define DM_EVENT_SECURITY_LOGON_FAIL      0x02000000
-#define DM_EVENT_SECURITY                 0x04000000
+#define DM_EVENT_SECURITY_LOGON_SUCCESS 0x01000000
+#define DM_EVENT_SECURITY_LOGON_FAIL    0x02000000
+#define DM_EVENT_SECURITY               0x04000000
 
 /* log all security related items */
-#define DM_EVENT_ALL_SECURITY             (DM_EVENT_SECURITY_LOGON_SUCCES |  
DM_EVENT_SECURITY_LOGON_FAIL | DM_EVENT_SECURITY)
+#define DM_EVENT_ALL_SECURITY (DM_EVENT_SECURITY_LOGON_SUCCES |  
DM_EVENT_SECURITY_LOGON_FAIL | DM_EVENT_SECURITY)
 
 
 /* log file flags (not event types) */
@@ -67,19 +70,19 @@
 #define DM_LOG_REQUIRE_TRANSACTIONS  0x00000003
 
 
-void init_datamonitor();
-void close_datamonitor();
+void init_datamonitor ();
+void close_datamonitor ();
 
-void add_datamonitor_logfile( const char *logfile ,
-                             unsigned long int events ,
-                             unsigned long int flags );
+void add_datamonitor_logfile (const gchar *logfile, guint32 events,
+                              guint32 flags);
 
 /* data access events */
-void dm_event( const char *username , const char *transactionid ,
-              unsigned long int event , ... );
+void dm_event (const gchar *username, const gchar *transactionid,
+               guint32 event, ...);
 
 /* generic loggable events */
-void dm_logentry ( unsigned long int type , const char *username , const char 
*fmt , ... );
-void dm_vlogentry( unsigned long int type , const char *username , const char 
*fmt , va_list a );
+void dm_logentry (guint32 type, const gchar *username, const gchar *fmt, ...);
+void dm_vlogentry (guint32 type, const gchar *username,
+                   const gchar *fmt, va_list a);
 
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]