aboutsummaryrefslogtreecommitdiff
path: root/log.cc
diff options
context:
space:
mode:
Diffstat (limited to 'log.cc')
-rw-r--r--log.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/log.cc b/log.cc
index 3370959..84f34d7 100644
--- a/log.cc
+++ b/log.cc
@@ -4,6 +4,8 @@
#include <iomanip>
#include "log.h"
+#include <sstream>
+
namespace nitrokey {
namespace log {
@@ -39,5 +41,21 @@ namespace nitrokey {
<< std::put_time(&tm, "%c %z")
<< "]\t" << str << std::endl;
}
+
+ void FunctionalLogHandler::print(const std::string &str, Loglevel lvl) {
+ std::time_t t = std::time(nullptr);
+ std::tm tm = *std::localtime(&t);
+
+ std::stringstream s;
+ s << "[" << loglevel_to_str(lvl) << "] ["
+ << std::put_time(&tm, "%c %z")
+ << "]\t" << str << std::endl;
+
+ log_function(s.str());
+ }
+
+ FunctionalLogHandler::FunctionalLogHandler(std::function<void(std::string)> _log_function) {
+ log_function = _log_function;
+ }
}
}