Pull logging prefix from program name from argv[0]

This commit is contained in:
Michael Jumper 2012-03-15 22:23:55 -07:00
parent a1397c53dc
commit 6373580830
3 changed files with 11 additions and 2 deletions

View File

@ -40,6 +40,7 @@
#include <guacamole/client.h>
extern char log_prefix[64];
void vguacd_log_info(const char* format, va_list args);
void vguacd_log_error(const char* format, va_list args);

View File

@ -48,6 +48,7 @@
#include <errno.h>
#include <syslog.h>
#include <libgen.h>
#include <guacamole/client.h>
#include <guacamole/error.h>
@ -227,6 +228,10 @@ int main(int argc, char* argv[]) {
}
}
/* Set up logging prefix */
strncpy(log_prefix, basename(argv[0]), sizeof(log_prefix));
/* Get addresses for binding */
if ((retval = getaddrinfo(listen_address, listen_port, &hints, &addresses))) {
guacd_log_error("Error parsing given address or port: %s",

View File

@ -45,6 +45,9 @@
#include <guacamole/client.h>
#include <guacamole/error.h>
/* Log prefix, defaulting to "guacd" */
char log_prefix[64] = "guacd";
void vguacd_log_info(const char* format, va_list args) {
/* Copy log message into buffer */
@ -55,7 +58,7 @@ void vguacd_log_info(const char* format, va_list args) {
syslog(LOG_INFO, "%s", message);
/* Log to STDERR */
fprintf(stderr, "guacd[%i]: INFO: %s\n", getpid(), message);
fprintf(stderr, "%s[%i]: INFO: %s\n", log_prefix, getpid(), message);
}
@ -69,7 +72,7 @@ void vguacd_log_error(const char* format, va_list args) {
syslog(LOG_ERR, "%s", message);
/* Log to STDERR */
fprintf(stderr, "guacd[%i]: ERROR: %s\n", getpid(), message);
fprintf(stderr, "%s[%i]: ERROR: %s\n", log_prefix, getpid(), message);
}