X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Flog.c;h=5d2af2b8bf295e2b80f1fc0c7c6dfcdd540c8563;hb=a8ca900b2e60cc837c5e9529d7a9c778ff30c955;hp=9eb5981d1ea9d01a67683fbf0d24109018e1dd9e;hpb=5191e1cb38d24ebf5c180ac7911893ca8bc4031f;p=umurmur.git diff --git a/src/log.c b/src/log.c index 9eb5981..5d2af2b 100644 --- a/src/log.c +++ b/src/log.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2010, Martin Johansson +/* Copyright (C) 2009-2010, Martin Johansson Copyright (C) 2005-2010, Thorvald Natvig All rights reserved. @@ -37,7 +37,7 @@ #include "log.h" -#define BUFSIZE 254 +#define STRSIZE 254 static bool_t termprint; @@ -58,84 +58,100 @@ void Log_free() void logthis(const char *logstring, ...) { va_list argp; - char buf[BUFSIZE + 2]; + char buf[STRSIZE + 1]; va_start(argp, logstring); - vsnprintf(&buf[0], BUFSIZE, logstring, argp); + vsnprintf(&buf[0], STRSIZE, logstring, argp); va_end(argp); - strcat(buf, "\n"); if (termprint) - fprintf(stderr, "%s", buf); /* XXX - other targets for logging */ + fprintf(stderr, "%s\n", buf); else - syslog(LOG_INFO, buf); + syslog(LOG_INFO, "%s", buf); } void Log_warn(const char *logstring, ...) { va_list argp; - char buf[BUFSIZE + 2]; + char buf[STRSIZE + 1]; int offset = 0; va_start(argp, logstring); offset = sprintf(buf, "WARN: "); - vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp); + vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp); va_end(argp); - strcat(buf, "\n"); if (termprint) - fprintf(stderr, "%s", buf); /* XXX - other targets for logging */ + fprintf(stderr, "%s\n", buf); else - syslog(LOG_WARNING, buf); + syslog(LOG_WARNING, "%s", buf); } void Log_info(const char *logstring, ...) { va_list argp; - char buf[BUFSIZE + 2]; + char buf[STRSIZE + 1]; int offset = 0; va_start(argp, logstring); offset = sprintf(buf, "INFO: "); - vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp); + vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp); va_end(argp); - strcat(buf, "\n"); if (termprint) - fprintf(stderr, "%s", buf); /* XXX - other targets for logging */ + fprintf(stderr, "%s\n", buf); else - syslog(LOG_INFO, buf); + syslog(LOG_INFO, "%s", buf); +} +void Log_info_client(client_t *client, const char *logstring, ...) +{ + va_list argp; + char buf[STRSIZE + 1]; + int offset = 0; + + va_start(argp, logstring); + offset = sprintf(buf, "INFO: "); + offset += vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp); + va_end(argp); + offset += snprintf(&buf[offset], STRSIZE - offset, " - [%d] %s@%s:%d", + client->sessionId, + client->username == NULL ? "" : client->username, + inet_ntoa(client->remote_tcp.sin_addr), + ntohs(client->remote_tcp.sin_port)); + if (termprint) + fprintf(stderr, "%s\n", buf); + else + syslog(LOG_INFO, "%s", buf); + } #ifdef DEBUG void Log_debug(const char *logstring, ...) { va_list argp; - char buf[BUFSIZE + 2]; + char buf[STRSIZE + 1]; int offset = 0; va_start(argp, logstring); offset = sprintf(buf, "DEBUG: "); - vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp); + vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp); va_end(argp); - strcat(buf, "\n"); if (termprint) - fprintf(stderr, "%s", buf); /* XXX - other targets for logging */ + fprintf(stderr, "%s\n", buf); else - syslog(LOG_DEBUG, buf); + syslog(LOG_DEBUG, "%s", buf); } #endif void Log_fatal(const char *logstring, ...) { va_list argp; - char buf[BUFSIZE + 2]; + char buf[STRSIZE + 1]; int offset = 0; va_start(argp, logstring); offset = sprintf(buf, "FATAL: "); - vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp); + vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp); va_end(argp); - strcat(buf, "\n"); if (termprint) - fprintf(stderr, "%s", buf); /* XXX - other targets for logging */ + fprintf(stderr, "%s\n", buf); else - syslog(LOG_CRIT, buf); + syslog(LOG_CRIT, "%s", buf); exit(1); }