Add va_list variants of the guac_log_* functions

This commit is contained in:
Michael Jumper 2011-03-20 00:21:56 -07:00
parent 97a63fae3e
commit 220035746b
2 changed files with 53 additions and 21 deletions

View File

@ -50,10 +50,22 @@
* log to syslog for platforms supporting it, and stderr for * log to syslog for platforms supporting it, and stderr for
* all others. * all others.
* *
* @param str A printf-style format string to log. * @param format A printf-style format string to log.
* @param ... Arguments to use when filling the format string for printing. * @param ... Arguments to use when filling the format string for printing.
*/ */
void guac_log_info(const char* str, ...); void guac_log_info(const char* format, ...);
/**
* Logs an informational message in the system log, whatever
* that may be for the system being used. This will currently
* log to syslog for platforms supporting it, and stderr for
* all others.
*
* @param format A printf-style format string to log.
* @param ap The va_list containing the arguments to be used when filling the
* format string for printing.
*/
void vguac_log_info(const char* format, va_list ap);
/** /**
* Logs an error message in the system log, whatever * Logs an error message in the system log, whatever
@ -61,9 +73,21 @@ void guac_log_info(const char* str, ...);
* log to syslog for platforms supporting it, and stderr for * log to syslog for platforms supporting it, and stderr for
* all others. * all others.
* *
* @param str A printf-style format string to log. * @param format A printf-style format string to log.
* @param ... Arguments to use when filling the format string for printing. * @param ... Arguments to use when filling the format string for printing.
*/ */
void guac_log_error(const char* str, ...); void guac_log_error(const char* format, ...);
/**
* Logs an error message in the system log, whatever
* that may be for the system being used. This will currently
* log to syslog for platforms supporting it, and stderr for
* all others.
*
* @param format A printf-style format string to log.
* @param ap The va_list containing the arguments to be used when filling the
* format string for printing.
*/
void vguac_log_error(const char* format, va_list ap);
#endif #endif

View File

@ -45,35 +45,43 @@
#include "log.h" #include "log.h"
void guac_log_info(const char* str, ...) { void vguac_log_info(const char* format, va_list ap) {
va_list args;
va_start(args, str);
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
vsyslog(LOG_ERR, str, args); vsyslog(LOG_ERR, format, ap);
#else #else
fprintf(stderr, "guacamole: info: "); fprintf(stderr, "guacamole: info: ");
vfprintf(stderr, str, args); vfprintf(stderr, format, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#endif #endif
va_end(args);
} }
void guac_log_error(const char* str, ...) { void vguac_log_error(const char* format, va_list ap) {
va_list args;
va_start(args, str);
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
vsyslog(LOG_INFO, str, args); vsyslog(LOG_INFO, format, ap);
#else #else
fprintf(stderr, "guacamole: error: "); fprintf(stderr, "guacamole: error: ");
vfprintf(stderr, str, args); vfprintf(stderr, format, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#endif #endif
}
void guac_log_info(const char* format, ...) {
va_list args;
va_start(args, format);
vguac_log_info(format, args);
va_end(args);
}
void guac_log_error(const char* format, ...) {
va_list args;
va_start(args, format);
vguac_log_error(format, args);
va_end(args); va_end(args);