summaryrefslogtreecommitdiff
path: root/src/libcharon/bus
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2015-11-18 14:49:27 +0100
committerYves-Alexis Perez <corsac@debian.org>2015-11-18 14:49:27 +0100
commit1e980d6be0ef0e243c6fe82b5e855454b97e24a4 (patch)
tree0d59eec2ce2ed332434ae80fc78a44db9ad293c5 /src/libcharon/bus
parent5dca9ea0e2931f0e2a056c7964d311bcc30a01b8 (diff)
downloadvyos-strongswan-1e980d6be0ef0e243c6fe82b5e855454b97e24a4.tar.gz
vyos-strongswan-1e980d6be0ef0e243c6fe82b5e855454b97e24a4.zip
Imported Upstream version 5.3.4
Diffstat (limited to 'src/libcharon/bus')
-rw-r--r--src/libcharon/bus/listeners/file_logger.c32
-rw-r--r--src/libcharon/bus/listeners/file_logger.h7
2 files changed, 30 insertions, 9 deletions
diff --git a/src/libcharon/bus/listeners/file_logger.c b/src/libcharon/bus/listeners/file_logger.c
index e3661bde6..7a53e9338 100644
--- a/src/libcharon/bus/listeners/file_logger.c
+++ b/src/libcharon/bus/listeners/file_logger.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
* Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -65,6 +65,11 @@ struct private_file_logger_t {
char *time_format;
/**
+ * Add milliseconds after the time string
+ */
+ bool add_ms;
+
+ /**
* Print the name/# of the IKE_SA?
*/
bool ike_name;
@@ -87,7 +92,9 @@ METHOD(logger_t, log_, void,
char timestr[128], namestr[128] = "";
const char *current = message, *next;
struct tm tm;
- time_t t;
+ timeval_t tv;
+ time_t s;
+ u_int ms = 0;
this->lock->read_lock(this->lock);
if (!this->out)
@@ -97,8 +104,10 @@ METHOD(logger_t, log_, void,
}
if (this->time_format)
{
- t = time(NULL);
- localtime_r(&t, &tm);
+ gettimeofday(&tv, NULL);
+ s = tv.tv_sec;
+ ms = tv.tv_usec / 1000;
+ localtime_r(&s, &tm);
strftime(timestr, sizeof(timestr), this->time_format, &tm);
}
if (this->ike_name && ike_sa)
@@ -126,8 +135,16 @@ METHOD(logger_t, log_, void,
next = strchr(current, '\n');
if (this->time_format)
{
- fprintf(this->out, "%s %.2d[%N]%s ",
- timestr, thread, debug_names, group, namestr);
+ if (this->add_ms)
+ {
+ fprintf(this->out, "%s.%03u %.2d[%N]%s ",
+ timestr, ms, thread, debug_names, group, namestr);
+ }
+ else
+ {
+ fprintf(this->out, "%s %.2d[%N]%s ",
+ timestr, thread, debug_names, group, namestr);
+ }
}
else
{
@@ -182,11 +199,12 @@ METHOD(file_logger_t, set_level, void,
}
METHOD(file_logger_t, set_options, void,
- private_file_logger_t *this, char *time_format, bool ike_name)
+ private_file_logger_t *this, char *time_format, bool add_ms, bool ike_name)
{
this->lock->write_lock(this->lock);
free(this->time_format);
this->time_format = strdupnull(time_format);
+ this->add_ms = add_ms;
this->ike_name = ike_name;
this->lock->unlock(this->lock);
}
diff --git a/src/libcharon/bus/listeners/file_logger.h b/src/libcharon/bus/listeners/file_logger.h
index 9e5aed50b..1bcfec150 100644
--- a/src/libcharon/bus/listeners/file_logger.h
+++ b/src/libcharon/bus/listeners/file_logger.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
* Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -48,9 +48,12 @@ struct file_logger_t {
* Set options used by this logger
*
* @param time_format format of timestamp prefix, as in strftime(), cloned
+ * @param add_ms TRUE to add the number of milliseconds within the
+ * current second after the timestamp
* @param ike_name TRUE to prefix the name of the IKE_SA
*/
- void (*set_options) (file_logger_t *this, char *time_format, bool ike_name);
+ void (*set_options) (file_logger_t *this, char *time_format, bool add_ms,
+ bool ike_name);
/**
* Open (or reopen) the log file according to the given parameters