Using function rather than variadic macro

This commit is contained in:
Michael Jumper 2011-03-19 17:02:30 -07:00
parent a72df19449
commit 06dad71273
3 changed files with 93 additions and 22 deletions

View File

@ -38,19 +38,7 @@
#ifndef _GUAC_LOG_H
#define _GUAC_LOG_H
#ifdef HAVE_SYSLOG_H
/* Logging for UNIX */
#include <syslog.h>
#define GUAC_LOG_ERROR(...) syslog(LOG_ERR, __VA_ARGS__)
#define GUAC_LOG_INFO(...) syslog(LOG_INFO, __VA_ARGS__)
#else
/* Logging for W32 */
#define GUAC_LOG_ERROR(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
#define GUAC_LOG_INFO(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
#endif
void guac_log_info(const char* str, ...);
void guac_log_error(const char* str, ...);
#endif

View File

@ -156,7 +156,7 @@ guac_client* guac_get_client(int client_fd) {
/* Load client plugin */
client->client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY);
if (!(client->client_plugin_handle)) {
GUAC_LOG_ERROR("Could not open client plugin for protocol \"%s\": %s\n", protocol, dlerror());
guac_log_error("Could not open client plugin for protocol \"%s\": %s\n", protocol, dlerror());
guac_send_error(io, "Could not load server-side client plugin.");
guac_flush(io);
guac_close(io);
@ -170,7 +170,7 @@ guac_client* guac_get_client(int client_fd) {
alias.obj = dlsym(client->client_plugin_handle, "guac_client_init");
if ((error = dlerror()) != NULL) {
GUAC_LOG_ERROR("Could not get guac_client_init in plugin: %s\n", error);
guac_log_error("Could not get guac_client_init in plugin: %s\n", error);
guac_send_error(io, "Invalid server-side client plugin.");
guac_flush(io);
guac_close(io);
@ -182,7 +182,7 @@ guac_client* guac_get_client(int client_fd) {
client_args = (const char**) dlsym(client->client_plugin_handle, "GUAC_CLIENT_ARGS");
if ((error = dlerror()) != NULL) {
GUAC_LOG_ERROR("Could not get GUAC_CLIENT_ in plugin: %s\n", error);
guac_log_error("Could not get GUAC_CLIENT_ in plugin: %s\n", error);
guac_send_error(io, "Invalid server-side client plugin.");
guac_flush(io);
guac_close(io);
@ -230,7 +230,7 @@ guac_client* guac_get_client(int client_fd) {
result = guac_read_instruction(io, &instruction);
if (result < 0) {
GUAC_LOG_ERROR("Error reading instruction while waiting for connect");
guac_log_error("Error reading instruction while waiting for connect");
guac_close(io);
return NULL;
}
@ -271,14 +271,14 @@ void guac_free_client(guac_client* client) {
if (client->free_handler) {
if (client->free_handler(client))
GUAC_LOG_ERROR("Error calling client free handler");
guac_log_error("Error calling client free handler");
}
guac_close(client->io);
/* Unload client plugin */
if (dlclose(client->client_plugin_handle)) {
GUAC_LOG_ERROR("Could not close client plugin while unloading client: %s", dlerror());
guac_log_error("Could not close client plugin while unloading client: %s", dlerror());
}
free(client);
@ -318,8 +318,9 @@ void* __guac_client_output_thread(void* data) {
int retval = client->handle_messages(client);
if (retval) {
GUAC_LOG_ERROR("Error handling server messages");
break;
guac_log_error("Error handling server messages");
guac_client_stop(client);
return NULL;
}
/* If data was written during message handling */

82
libguac/src/log.c Normal file
View File

@ -0,0 +1,82 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is libguac.
*
* The Initial Developer of the Original Code is
* Michael Jumper.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
#include <stdio.h>
#endif
#include <stdarg.h>
#include "log.h"
void guac_log_info(const char* str, ...) {
va_list args;
va_start(args, str);
#ifdef HAVE_SYSLOG_H
vsyslog(LOG_ERR, str, args);
#else
fprintf(stderr, "guacamole: info: ");
vfprintf(stderr, str, args);
fprintf(stderr, "\n");
#endif
va_end(args);
}
void guac_log_error(const char* str, ...) {
va_list args;
va_start(args, str);
#ifdef HAVE_SYSLOG_H
vsyslog(LOG_INFO, str, args);
#else
fprintf(stderr, "guacamole: error: ");
vfprintf(stderr, str, args);
fprintf(stderr, "\n");
#endif
va_end(args);
}
#endif