/*
logger.c -- logging code
- Copyright (C) 2004-2012 Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2004-2015 Guus Sliepen <guus@tinc-vpn.org>
2004-2005 Ivo Timmermans
This program is free software; you can redistribute it and/or modify
#include "conf.h"
#include "meta.h"
+#include "names.h"
#include "logger.h"
#include "connection.h"
#include "control_common.h"
debug_t debug_level = DEBUG_NOTHING;
static logmode_t logmode = LOGMODE_STDERR;
static pid_t logpid;
-extern char *logfilename;
static FILE *logfile = NULL;
#ifdef HAVE_MINGW
static HANDLE loghandle = NULL;
case LOGMODE_FILE:
if(!now.tv_sec)
gettimeofday(&now, NULL);
- strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now.tv_sec));
+ time_t now_sec = now.tv_sec;
+ strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now_sec));
fprintf(logfile, "%s %s[%ld]: %s\n", timestr, logident, (long)logpid, message);
fflush(logfile);
break;
static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap) {
char message[1024] = "";
- int len = vsnprintf(message, sizeof message, format, ap);
- if(len > 0 && len < sizeof message && message[len - 1] == '\n')
- message[len - 1] = 0;
+ size_t msglen = sizeof message;
+
+ int len = vsnprintf(message, msglen, format, ap);
+ if(len > 0 && len < sizeof message) {
+ if(message[len - 1] == '\n')
+ message[--len] = 0;
+
+ connection_t *c = s->handle;
+ if(c)
+ snprintf(message + len, sizeof message - len, " from %s (%s)", c->name, c->hostname);
+ }
real_logger(DEBUG_ALWAYS, LOG_ERR, message);
}