Re: [gnome-db] win32 log changes.



Ok, lets try with a diff... :)

Alan Knowles wrote:

Attached for review (do not commit yet - I havent tested it..)
- changes to gda-log.c to enable win32 syslog type features.

I've based the code off of.
http://cvs.php.net/co.php/php-src/win32/wsyslog.c?r=1.6

Since I know almost nothing of Win32 - it's just a best guess..

Key points to consider:
- a WIN32 compile flag  - I've used GDA_WIN32
- bothering win32 syslog? - It would probably be alot easier to maintain if it just fell back to g_log().. I've no idea how much gda-log is used in the code.. From what I understand, you have to add stuff to the registry to allow a program to log to it, which for me sounds like quite a bit of hastle, not worth bothering with...

Regards
Alan

_______________________________________________
gnome-db-list mailing list
gnome-db-list gnome org
http://mail.gnome.org/mailman/listinfo/gnome-db-list


? log.win32
Index: libgda/gda-log.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-log.c,v
retrieving revision 1.11
diff -u -r1.11 gda-log.c
--- libgda/gda-log.c	1 Aug 2004 10:21:33 -0000	1.11
+++ libgda/gda-log.c	20 Sep 2004 06:49:20 -0000
@@ -19,7 +19,10 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#ifndef GDA_WIN32
 #include <syslog.h>
+#endif
+#include <process.h>
 #include <time.h>
 #include <glib/gmem.h>
 #include <glib/gmessages.h>
@@ -45,7 +48,9 @@
 {
 	log_enabled = TRUE;
 	if (!log_opened) {
+#ifndef GDA_WIN32	
 		openlog (g_get_prgname (), LOG_CONS | LOG_NOWAIT | LOG_PID, LOG_USER);
+#endif		
 		log_opened = TRUE;
 	}
 }
@@ -60,7 +65,9 @@
 {
 	log_enabled = FALSE;
 	if (log_opened) {
+#ifndef GDA_WIN32		
 		closelog ();
+#endif
 		log_opened = FALSE;
 	}
 }
@@ -101,8 +108,24 @@
 	va_start (args, format);
 	msg = g_strdup_vprintf (format, args);
 	va_end (args);
-
+#ifdef GDA_WIN32
+	{
+		char *gda_win32_log_source;
+		char *gda_win32_log_header;
+		LPTSTR strs[2];
+		RegisterEventSource(NULL, "LibGda-" GDA_VERSION);
+		/* potental memory leak?? - is getpid + ident going to be greater than 256? */
+		gda_win32_log_header = malloc(256);
+		sprintf(gda_win32_log_header, "%s[%d]", g_get_prgname (), getpid());
+		strs[0] = gda_win32_log_header; /* write header */  
+		strs[1] = msg; /* then the message */
+		ReportEvent(gda_win32_log_source , EVENTLOG_INFORMATION_TYPE, 1, 1, NULL, 2, 0, strs, NULL);
+		DeregisterEventSource(gda_win32_log_source);
+		free(gda_win32_log_header);
+	}
+#else
 	syslog (LOG_USER | LOG_INFO, msg);
+#endif
 	g_free (msg);
 }
 
@@ -131,7 +154,23 @@
 	va_start (args, format);
 	msg = g_strdup_vprintf (format, args);
 	va_end (args);
-
+#ifdef GDA_WIN32
+	{
+		char *gda_win32_log_source;
+		char *gda_win32_log_header;
+		LPTSTR strs[2];
+		RegisterEventSource(NULL, "LibGda-" GDA_VERSION);
+		/* potental memory leak?? - is getpid + ident going to be greater than 256? */
+		gda_win32_log_header = malloc(256);
+		sprintf(gda_win32_log_header, "%s[%d]", g_get_prgname (), getpid());
+		strs[0] = gda_win32_log_header; /* write header */  
+		strs[1] = msg; /* then the message */
+		ReportEvent(gda_win32_log_source , EVENTLOG_WARNING_TYPE, 1, 1, NULL, 2, 0, strs, NULL);
+		DeregisterEventSource(gda_win32_log_source);
+		free(gda_win32_log_header);
+	}
+#else
 	syslog (LOG_USER | LOG_ERR, msg);
-	g_free (msg);
+#endif
+ 	g_free (msg);
 }


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