New logging functions which log to both syslog and STDERR.
authorMichael Jumper <zhangmaike@users.sourceforge.net>
Fri, 16 Mar 2012 02:08:12 +0000 (19:08 -0700)
committerMichael Jumper <zhangmaike@users.sourceforge.net>
Fri, 16 Mar 2012 02:08:12 +0000 (19:08 -0700)
include/log.h
src/daemon.c
src/log.c

index 03b5560..1c31201 100644 (file)
 
 #include <guacamole/client.h>
 
 
 #include <guacamole/client.h>
 
-void guacd_log_info(guac_client* client, const char* format, va_list args);
-void guacd_log_error(guac_client* client, const char* format, va_list args);
+
+void vguacd_log_info(const char* format, va_list args);
+void vguacd_log_error(const char* format, va_list args);
+void guacd_log_info(const char* format, ...);
+void guacd_log_error(const char* format, ...);
+
+void guacd_client_log_info(guac_client* client, const char* format, va_list args);
+void guacd_client_log_error(guac_client* client, const char* format, va_list args);
+
 void guacd_log_guac_error(const char* message);
 void guacd_client_log_guac_error(guac_client* client, const char* message);
 
 void guacd_log_guac_error(const char* message);
 void guacd_client_log_guac_error(guac_client* client, const char* message);
 
index 0f692d2..9a3de23 100644 (file)
@@ -138,7 +138,7 @@ void guacd_handle_connection(int fd) {
     /* Load and init client */
     client = guac_client_plugin_get_client(plugin, socket,
             connect->argc, connect->argv,
     /* Load and init client */
     client = guac_client_plugin_get_client(plugin, socket,
             connect->argc, connect->argv,
-            guacd_log_info, guacd_log_error);
+            guacd_client_log_info, guacd_client_log_error);
 
     guac_instruction_free(connect);
 
 
     guac_instruction_free(connect);
 
index 6409c2c..bfd55db 100644 (file)
--- a/src/log.c
+++ b/src/log.c
 
 #include <errno.h>
 #include <syslog.h>
 
 #include <errno.h>
 #include <syslog.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include <guacamole/client.h>
 #include <guacamole/error.h>
 
 
 #include <guacamole/client.h>
 #include <guacamole/error.h>
 
-void guacd_log_info(guac_client* client, const char* format, va_list args) {
+void vguacd_log_info(const char* format, va_list args) {
+
+    /* Log to syslog */
     vsyslog(LOG_INFO, format, args);
     vsyslog(LOG_INFO, format, args);
+
+    /* Log to STDERR */
+    fprintf(stderr, "guacd[%i]: INFO:  ", getpid());
+    vfprintf(stderr, format, args);
+    fprintf(stderr, "\n");
+
 }
 
 }
 
-void guacd_log_error(guac_client* client, const char* format, va_list args) {
+void vguacd_log_error(const char* format, va_list args) {
+
+    /* Log to syslog */
     vsyslog(LOG_ERR, format, args);
     vsyslog(LOG_ERR, format, args);
+
+    /* Log to STDERR */
+    fprintf(stderr, "guacd[%i]: ERROR: ", getpid());
+    vfprintf(stderr, format, args);
+    fprintf(stderr, "\n");
+
+}
+
+void guacd_log_info(const char* format, ...) {
+    va_list args;
+    va_start(args, format);
+    vguacd_log_info(format, args);
+    va_end(args);
+}
+
+void guacd_log_error(const char* format, ...) {
+    va_list args;
+    va_start(args, format);
+    vguacd_log_error(format, args);
+    va_end(args);
+}
+
+void guacd_client_log_info(guac_client* client, const char* format,
+        va_list args) {
+    vguacd_log_info(format, args);
+}
+
+void guacd_client_log_error(guac_client* client, const char* format,
+        va_list args) {
+    vguacd_log_error(format, args);
 }
 
 void guacd_log_guac_error(const char* message) {
 
     /* If error message provided, include in log */
     if (guac_error_message != NULL)
 }
 
 void guacd_log_guac_error(const char* message) {
 
     /* If error message provided, include in log */
     if (guac_error_message != NULL)
-        syslog(LOG_ERR, "%s: %s: %s",
+        guacd_log_error("%s: %s: %s",
                 message,
                 guac_error_message,
                 guac_status_string(guac_error));
 
     /* Otherwise just log with standard status string */
     else
                 message,
                 guac_error_message,
                 guac_status_string(guac_error));
 
     /* Otherwise just log with standard status string */
     else
-        syslog(LOG_ERR, "%s: %s",
+        guacd_log_error("%s: %s",
                 message,
                 guac_status_string(guac_error));
 
                 message,
                 guac_status_string(guac_error));