From d0f6ed81de71f334154e02a33dcefa4f31dba246 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 15 Mar 2012 19:08:12 -0700 Subject: [PATCH] New logging functions which log to both syslog and STDERR. --- include/log.h | 11 +++++++++-- src/daemon.c | 2 +- src/log.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/include/log.h b/include/log.h index 03b5560..1c31201 100644 --- a/include/log.h +++ b/include/log.h @@ -40,8 +40,15 @@ #include -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); diff --git a/src/daemon.c b/src/daemon.c index 0f692d2..9a3de23 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -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, - guacd_log_info, guacd_log_error); + guacd_client_log_info, guacd_client_log_error); guac_instruction_free(connect); diff --git a/src/log.c b/src/log.c index 6409c2c..bfd55db 100644 --- a/src/log.c +++ b/src/log.c @@ -37,30 +37,74 @@ #include #include +#include +#include +#include +#include #include #include -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); + + /* 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); + + /* 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) - 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 - syslog(LOG_ERR, "%s: %s", + guacd_log_error("%s: %s", message, guac_status_string(guac_error)); -- 1.7.10.4