summaryrefslogtreecommitdiff
path: root/include/log.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-05-12 20:44:42 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2017-05-12 20:59:34 +0200
commitcc71df8100b33904d2c12a92fef237bebacbe1cd (patch)
tree9ebf7952d6f638e361169172d2041744888e0509 /include/log.h
parentebfcff1730b5db2ad85ad47c4ac3963581ef43ba (diff)
downloadlibnitrokey-cc71df8100b33904d2c12a92fef237bebacbe1cd.tar.gz
libnitrokey-cc71df8100b33904d2c12a92fef237bebacbe1cd.tar.bz2
Refactor log code
Inverse log levels order. Allow to change logging level with int. Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include/log.h')
-rw-r--r--include/log.h13
1 files changed, 10 insertions, 3 deletions
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<void(std::string)> log_function;
+ using log_function_type = std::function<void(std::string)>;
+ log_function_type log_function;
public:
- FunctionalLogHandler(std::function<void(std::string)> _log_function);
+ FunctionalLogHandler(log_function_type _log_function);
virtual void print(const std::string &, Loglevel lvl);
};