summaryrefslogtreecommitdiff
path: root/Logger.cpp
diff options
context:
space:
mode:
authorTobias Klauser <tobias.klauser@uzh.ch>2013-01-28 16:15:50 +0100
committerTobias Klauser <tklauser@distanz.ch>2013-01-28 16:33:08 +0100
commitd2fb8067167785b299482d247aaf90a35f55b62c (patch)
treed12fc756e9fecf935cbc46e1d6a3f89895868049 /Logger.cpp
parente5e089fe6c136d3962a066f9a8c7b56009459b16 (diff)
LocomotorPrimitives: Switch to using Logger class for logging
Diffstat (limited to 'Logger.cpp')
-rw-r--r--Logger.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/Logger.cpp b/Logger.cpp
new file mode 100644
index 0000000..b0850a6
--- /dev/null
+++ b/Logger.cpp
@@ -0,0 +1,58 @@
+/**
+ * General purpose logger class.
+ *
+ * Copyright (C) 2013 Tobias Klauser <tklauser@distanz.ch>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License, version 2.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include "Logger.h"
+
+const char *Logger::_LOGGER_DATE_FMT = "%b %d %Y %H:%M:%S";
+
+int Logger::_log_vfprintf(FILE *f, const char *prefix, const char *fmt, va_list ap)
+{
+ struct timeval now;
+ char buf[64];
+ int ret;
+
+ if (gettimeofday(&now, NULL))
+ return -EINVAL;
+
+ strftime(buf, sizeof(buf), _LOGGER_DATE_FMT, localtime(&now.tv_sec));
+ ret = fprintf(f, "[%s.%03lu] %s%s", buf, now.tv_usec / 1000,
+ prefix ? prefix : "", prefix ? ": " : "");
+
+ return vfprintf(f, fmt, ap);
+}
+
+int Logger::log(const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = _log_vfprintf(_f_out, NULL, fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
+
+int Logger::err(const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = _log_vfprintf(_f_err, "Error", fmt, ap);
+ va_end(ap);
+
+ return ret;
+}
/span>crypto: aead - Rename aead_alg to old_aead_algHerbert Xu1-12/+13 2015-05-22crypto: aead - Add new interface with single SG listHerbert Xu1-2/+56 2015-05-13crypto: aead - Convert top level interface to new styleHerbert Xu1-113/+48 2015-04-26crypto: aead - Fix corner case in crypto_lookup_aeadHerbert Xu1-1/+1 2014-12-22crypto: aead - fixed style error in aead.cJoshua I. James1-1/+2 2013-02-19crypto: user - fix info leaks in report APIMathias Krause1-5/+4 2013-02-04crypto: use ERR_CASTJulia Lawall1-4/+2 2012-04-10Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netDavid S. Miller1-2/+2 2012-04-02crypto: Stop using NLA_PUT*().David S. Miller1-6/+6 2012-03-29crypto: user - Fix lookup of algorithms with IV generatorSteffen Klassert1-2/+2 2011-11-11crypto: algapi - Fix build problem with NET disabledHerbert Xu1-0/+14 2011-10-21crypto: Add userspace report for nivaead type algorithmsSteffen Klassert1-0/+23 2011-10-21crypto: Add userspace report for aead type algorithmsSteffen Klassert1-0/+25