GUACAMOLE-175: Split logging between guacd and libguacd.

This commit is contained in:
Michael Jumper 2016-09-10 19:29:57 -07:00
parent d7a604c8b2
commit 45adc63597
15 changed files with 197 additions and 137 deletions

View File

@ -30,6 +30,7 @@ noinst_HEADERS = \
conf-file.h \
conf-parse.h \
connection.h \
log.h \
move-fd.h \
proc.h \
proc-map.h
@ -40,6 +41,7 @@ guacd_SOURCES = \
conf-parse.c \
connection.c \
daemon.c \
log.c \
move-fd.c \
proc.c \
proc-map.c

View File

@ -22,9 +22,9 @@
#include "connection.h"
#include "log.h"
#include "move-fd.h"
#include "libguacd/user.h"
#include "proc.h"
#include "proc-map.h"
#include "user.h"
#include <guacamole/client.h>
#include <guacamole/error.h>
@ -36,7 +36,7 @@
#ifdef ENABLE_SSL
#include <openssl/ssl.h>
#include "socket-ssl.h"
#include "libguacd/socket-ssl.h"
#endif
#include <errno.h>

View File

@ -22,9 +22,9 @@
#include "connection.h"
#include "conf-args.h"
#include "conf-file.h"
#include "libguacd/user.h"
#include "log.h"
#include "proc-map.h"
#include "user.h"
#ifdef ENABLE_SSL
#include <openssl/ssl.h>

143
src/guacd/log.c Normal file
View File

@ -0,0 +1,143 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "config.h"
#include "log.h"
#include <guacamole/client.h>
#include <guacamole/error.h>
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
#include <unistd.h>
int guacd_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;
char message[2048];
/* Don't bother if the log level is too high */
if (level > guacd_log_level)
return;
/* Copy log message into buffer */
vsnprintf(message, sizeof(message), format, args);
/* Convert log level to syslog priority */
switch (level) {
/* Error log level */
case GUAC_LOG_ERROR:
priority = LOG_ERR;
priority_name = "ERROR";
break;
/* Warning log level */
case GUAC_LOG_WARNING:
priority = LOG_WARNING;
priority_name = "WARNING";
break;
/* Informational log level */
case GUAC_LOG_INFO:
priority = LOG_INFO;
priority_name = "INFO";
break;
/* Debug log level */
case GUAC_LOG_DEBUG:
priority = LOG_DEBUG;
priority_name = "DEBUG";
break;
/* Any unknown/undefined log level */
default:
priority = LOG_INFO;
priority_name = "UNKNOWN";
break;
}
/* Log to syslog */
syslog(priority, "%s", message);
/* Log to STDERR */
fprintf(stderr, GUACD_LOG_NAME "[%i]: %s:\t%s\n",
getpid(), priority_name, message);
}
void guacd_log(guac_client_log_level level, const char* format, ...) {
va_list args;
va_start(args, format);
vguacd_log(level, format, args);
va_end(args);
}
void guacd_client_log(guac_client* client, guac_client_log_level level,
const char* format, va_list args) {
vguacd_log(level, format, args);
}
void guacd_log_guac_error(guac_client_log_level level, const char* message) {
if (guac_error != GUAC_STATUS_SUCCESS) {
/* If error message provided, include in log */
if (guac_error_message != NULL)
guacd_log(level, "%s: %s",
message,
guac_error_message);
/* Otherwise just log with standard status string */
else
guacd_log(level, "%s: %s",
message,
guac_status_string(guac_error));
}
/* Just log message if no status code */
else
guacd_log(level, "%s", message);
}
void guacd_log_handshake_failure() {
if (guac_error == GUAC_STATUS_CLOSED)
guacd_log(GUAC_LOG_INFO,
"Guacamole connection closed during handshake");
else if (guac_error == GUAC_STATUS_PROTOCOL_ERROR)
guacd_log(GUAC_LOG_ERROR,
"Guacamole protocol violation. Perhaps the version of "
"guacamole-client is incompatible with this version of "
"guacd?");
else
guacd_log(GUAC_LOG_WARNING,
"Guacamole handshake failed: %s",
guac_status_string(guac_error));
}

View File

@ -62,14 +62,6 @@ void guacd_client_log(guac_client* client, guac_client_log_level level,
*/
void guacd_log_guac_error(guac_client_log_level level, 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,
guac_client_log_level level, const char* message);
/**
* Logs a reasonable explanatory message regarding handshake failure based on
* the current value of guac_error.

View File

@ -19,9 +19,9 @@
#include "config.h"
#include "common/list.h"
#include "libguacd/user.h"
#include "proc.h"
#include "proc-map.h"
#include "user.h"
#include <guacamole/client.h>

View File

@ -23,8 +23,8 @@
#include "config.h"
#include "common/list.h"
#include "libguacd/user.h"
#include "proc.h"
#include "user.h"
#include <guacamole/client.h>

View File

@ -19,11 +19,11 @@
#include "config.h"
#include "libguacd/user.h"
#include "log.h"
#include "move-fd.h"
#include "proc.h"
#include "proc-map.h"
#include "user.h"
#include <guacamole/client.h>
#include <guacamole/error.h>

View File

@ -21,9 +21,9 @@ AUTOMAKE_OPTIONS = foreign
noinst_LTLIBRARIES = libguacd.la
noinst_HEADERS = \
log.h \
user.h
noinst_HEADERS = \
libguacd/log.h \
libguacd/user.h
libguacd_la_SOURCES = \
log.c \
@ -44,7 +44,7 @@ libguacd_la_LDFLAGS = \
# SSL support
if ENABLE_SSL
noinst_HEADERS += socket-ssl.h
noinst_HEADERS += libguacd/socket-ssl.h
libguacd_la_SOURCES += socket-ssl.c
endif

View File

@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef LIBGUACD_LOG_H
#define LIBGUACD_LOG_H
#include "config.h"
#include <guacamole/client.h>
/**
* 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,
guac_client_log_level level, const char* message);
#endif

View File

@ -18,8 +18,8 @@
*/
#ifndef _GUACD_USER_H
#define _GUACD_USER_H
#ifndef LIBGUACD_USER_H
#define LIBGUACD_USER_H
#include "config.h"

View File

@ -18,7 +18,7 @@
*/
#include "config.h"
#include "log.h"
#include "libguacd/log.h"
#include <guacamole/client.h>
#include <guacamole/error.h>
@ -28,102 +28,6 @@
#include <syslog.h>
#include <unistd.h>
int guacd_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;
char message[2048];
/* Don't bother if the log level is too high */
if (level > guacd_log_level)
return;
/* Copy log message into buffer */
vsnprintf(message, sizeof(message), format, args);
/* Convert log level to syslog priority */
switch (level) {
/* Error log level */
case GUAC_LOG_ERROR:
priority = LOG_ERR;
priority_name = "ERROR";
break;
/* Warning log level */
case GUAC_LOG_WARNING:
priority = LOG_WARNING;
priority_name = "WARNING";
break;
/* Informational log level */
case GUAC_LOG_INFO:
priority = LOG_INFO;
priority_name = "INFO";
break;
/* Debug log level */
case GUAC_LOG_DEBUG:
priority = LOG_DEBUG;
priority_name = "DEBUG";
break;
/* Any unknown/undefined log level */
default:
priority = LOG_INFO;
priority_name = "UNKNOWN";
break;
}
/* Log to syslog */
syslog(priority, "%s", message);
/* Log to STDERR */
fprintf(stderr, GUACD_LOG_NAME "[%i]: %s:\t%s\n",
getpid(), priority_name, message);
}
void guacd_log(guac_client_log_level level, const char* format, ...) {
va_list args;
va_start(args, format);
vguacd_log(level, format, args);
va_end(args);
}
void guacd_client_log(guac_client* client, guac_client_log_level level,
const char* format, va_list args) {
vguacd_log(level, format, args);
}
void guacd_log_guac_error(guac_client_log_level level, const char* message) {
if (guac_error != GUAC_STATUS_SUCCESS) {
/* If error message provided, include in log */
if (guac_error_message != NULL)
guacd_log(level, "%s: %s",
message,
guac_error_message);
/* Otherwise just log with standard status string */
else
guacd_log(level, "%s: %s",
message,
guac_status_string(guac_error));
}
/* Just log message if no status code */
else
guacd_log(level, "%s", message);
}
void guacd_client_log_guac_error(guac_client* client,
guac_client_log_level level, const char* message) {
@ -149,20 +53,3 @@ void guacd_client_log_guac_error(guac_client* client,
}
void guacd_log_handshake_failure() {
if (guac_error == GUAC_STATUS_CLOSED)
guacd_log(GUAC_LOG_INFO,
"Guacamole connection closed during handshake");
else if (guac_error == GUAC_STATUS_PROTOCOL_ERROR)
guacd_log(GUAC_LOG_ERROR,
"Guacamole protocol violation. Perhaps the version of "
"guacamole-client is incompatible with this version of "
"guacd?");
else
guacd_log(GUAC_LOG_WARNING,
"Guacamole handshake failed: %s",
guac_status_string(guac_error));
}

View File

@ -19,7 +19,7 @@
#include "config.h"
#include "socket-ssl.h"
#include "libguacd/socket-ssl.h"
#include <poll.h>
#include <stdlib.h>

View File

@ -19,8 +19,8 @@
#include "config.h"
#include "log.h"
#include "user.h"
#include "libguacd/log.h"
#include "libguacd/user.h"
#include <guacamole/client.h>
#include <guacamole/error.h>