From b2dec03e9b3df59550e598906a76e51bf721afa6 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 7 Apr 2017 07:06:13 +0200 Subject: Handle print function in logger by functor Signed-off-by: Szczepan Zalega --- include/NitrokeyManager.h | 1 + include/log.h | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'include') diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index a815571..51cd966 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -139,6 +139,7 @@ namespace nitrokey { int get_minor_firmware_version(); explicit NitrokeyManager(); + void set_log_function(std::function log_function); private: static shared_ptr _instance; diff --git a/include/log.h b/include/log.h index 38fc122..e7c790a 100644 --- a/include/log.h +++ b/include/log.h @@ -4,6 +4,8 @@ #include #include +#include + namespace nitrokey { namespace log { @@ -29,6 +31,14 @@ namespace nitrokey { virtual void print(const std::string &, Loglevel lvl); }; + class FunctionalLogHandler : public LogHandler { + std::function log_function; + public: + FunctionalLogHandler(std::function _log_function); + virtual void print(const std::string &, Loglevel lvl); + + }; + extern StdlogHandler stdlog_handler; class Log { @@ -56,8 +66,10 @@ namespace nitrokey { #ifdef NO_LOG #define LOG(string, level) while(false){} +#define LOGD(string, level) while(false){} #else #define LOG(string, level) nitrokey::log::Log::instance()((string), (level)) +#define LOGD(string) nitrokey::log::Log::instance()((string), (nitrokey::log::Loglevel::DEBUG_L2)) #endif #endif -- cgit v1.2.3