-/* Copyright (C) 2009, Martin Johansson <martin@fatbob.nu>
- Copyright (C) 2005-2009, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2010, Martin Johansson <martin@fatbob.nu>
+ Copyright (C) 2005-2010, Thorvald Natvig <thorvald@natvig.com>
All rights reserved.
#include "log.h"
-#define BUFSIZE 254
+#define STRSIZE 254
static bool_t termprint;
{
termprint = terminal;
if (!termprint)
- openlog("uMurmud", LOG_PID, LOG_DAEMON);
+ openlog("uMurmurd", LOG_PID, LOG_DAEMON);
}
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_ALERT, 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_ALERT, 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_INFO, 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_INFO, buf);
+ syslog(LOG_CRIT, "%s", buf);
exit(1);
}