diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-04-07 07:06:13 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-04-07 07:06:13 +0200 |
commit | b2dec03e9b3df59550e598906a76e51bf721afa6 (patch) | |
tree | 604f6a258f90af0c46f84ded5522952d13072d82 /log.cc | |
parent | d5ad36fab5ea6270ff6b0a8b14f8ce10f0fb3c34 (diff) | |
download | libnitrokey-b2dec03e9b3df59550e598906a76e51bf721afa6.tar.gz libnitrokey-b2dec03e9b3df59550e598906a76e51bf721afa6.tar.bz2 |
Handle print function in logger by functor
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'log.cc')
-rw-r--r-- | log.cc | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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; + } } } |