GUAC-911: Only log up to specified log level. Add comments to log.h.

This commit is contained in:
Michael Jumper 2014-11-09 17:04:25 -08:00
parent 049c366b78
commit c3f98b388a
3 changed files with 47 additions and 3 deletions

View File

@ -392,7 +392,8 @@ int main(int argc, char* argv[]) {
/* Set up logging prefix */
strncpy(log_prefix, basename(argv[0]), sizeof(log_prefix));
/* Open log as early as we can */
/* Init logging as early as possible */
log_level = config->max_log_level;
openlog("guacd", LOG_PID, LOG_DAEMON);
/* Log start */

View File

@ -21,6 +21,7 @@
*/
#include "config.h"
#include "log.h"
#include <guacamole/client.h>
#include <guacamole/error.h>
@ -33,14 +34,21 @@
/* Log prefix, defaulting to "guacd" */
char log_prefix[64] = "guacd";
int log_level = GUAC_LOG_INFO;
void vguacd_log(guac_client_log_level level, const char* format,
va_list args) {
const char* priority_name;
int priority;
/* Copy log message into buffer */
char message[2048];
/* Don't bother if the log level is too high */
if (level > log_level)
return;
/* Copy log message into buffer */
vsnprintf(message, sizeof(message), format, args);
/* Convert log level to syslog priority */

View File

@ -28,14 +28,49 @@
#include <guacamole/client.h>
/**
* The maximum level at which to log messages. All other messages will be
* dropped.
*/
extern int log_level;
/**
* The string to prepend to all log messages.
*/
extern char log_prefix[64];
/**
* Writes a message to guacd's logs. This function takes a format and va_list,
* similar to vprintf.
*/
void vguacd_log(guac_client_log_level level, const char* format, va_list args);
/**
* Writes a message to guacd's logs. This function accepts parameters
* identically to printf.
*/
void guacd_log(guac_client_log_level level, const char* format, ...);
void guacd_client_log(guac_client* client, guac_client_log_level level, const char* format, va_list args);
/**
* Writes a message using the logging facilities of the given client,
* automatically including any information present in guac_error. This function
* accepts parameters identically to printf.
*/
void guacd_client_log(guac_client* client, guac_client_log_level level,
const char* format, va_list args);
/**
* Prints an error message to guacd's logs, automatically including any
* information present in guac_error. This function accepts parameters
* identically to printf.
*/
void guacd_log_guac_error(const char* message);
/**
* Prints an error message using the logging facilities of the given client,
* automatically including any information present in guac_error. This function
* accepts parameters identically to printf.
*/
void guacd_client_log_guac_error(guac_client* client, const char* message);
#endif