From cc71df8100b33904d2c12a92fef237bebacbe1cd Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 12 May 2017 20:44:42 +0200 Subject: Refactor log code Inverse log levels order. Allow to change logging level with int. Signed-off-by: Szczepan Zalega --- include/NitrokeyManager.h | 2 ++ include/log.h | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index e3dcc45..de14fbc 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -179,6 +179,8 @@ char * strndup(const char* str, size_t maxlen); public: bool set_current_device_speed(int retry_delay, int send_receive_delay); void set_loglevel(Loglevel loglevel); + + void set_loglevel(int loglevel); }; } diff --git a/include/log.h b/include/log.h index e7c790a..e559845 100644 --- a/include/log.h +++ b/include/log.h @@ -16,7 +16,11 @@ namespace nitrokey { enum class Loglevel : int { - DEBUG_L2, DEBUG, INFO, WARNING, ERROR + ERROR, + WARNING, + INFO, + DEBUG, + DEBUG_L2 }; class LogHandler { @@ -24,6 +28,8 @@ namespace nitrokey { virtual void print(const std::string &, Loglevel lvl) = 0; protected: std::string loglevel_to_str(Loglevel); + std::string format_message_to_string(const std::string &str, const Loglevel &lvl); + }; class StdlogHandler : public LogHandler { @@ -32,9 +38,10 @@ namespace nitrokey { }; class FunctionalLogHandler : public LogHandler { - std::function log_function; + using log_function_type = std::function; + log_function_type log_function; public: - FunctionalLogHandler(std::function _log_function); + FunctionalLogHandler(log_function_type _log_function); virtual void print(const std::string &, Loglevel lvl); }; -- cgit v1.2.1