New logging functions which log to both syslog and STDERR.

This commit is contained in:
Michael Jumper 2012-03-15 19:08:12 -07:00
parent 82694ec45f
commit 9f24a3f377
3 changed files with 58 additions and 7 deletions

View File

@ -40,8 +40,15 @@
#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_log_guac_error(const char* message);
void guacd_client_log_guac_error(guac_client* client, const char* message); void guacd_client_log_guac_error(guac_client* client, const char* message);

View File

@ -138,7 +138,7 @@ void guacd_handle_connection(int fd) {
/* Load and init client */ /* Load and init client */
client = guac_client_plugin_get_client(plugin, socket, client = guac_client_plugin_get_client(plugin, socket,
connect->argc, connect->argv, 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);

View File

@ -37,30 +37,74 @@
#include <errno.h> #include <errno.h>
#include <syslog.h> #include <syslog.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/error.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) { void guacd_log_guac_error(const char* message) {
/* If error message provided, include in log */ /* If error message provided, include in log */
if (guac_error_message != NULL) if (guac_error_message != NULL)
syslog(LOG_ERR, "%s: %s: %s", guacd_log_error("%s: %s: %s",
message, message,
guac_error_message, guac_error_message,
guac_status_string(guac_error)); guac_status_string(guac_error));
/* Otherwise just log with standard status string */ /* Otherwise just log with standard status string */
else else
syslog(LOG_ERR, "%s: %s", guacd_log_error("%s: %s",
message, message,
guac_status_string(guac_error)); guac_status_string(guac_error));