aboutsummaryrefslogtreecommitdiff
path: root/log.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-02-16 15:17:47 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2018-02-28 20:07:14 +0100
commit38c3b4c58e6c6b86d6241183be1814bac2e037d2 (patch)
tree2f5dd6ea25a64f446133c48209ceb53fd4615d71 /log.cc
parentd6ae8192be443749fcd1f593db0f9be4d039da93 (diff)
downloadlibnitrokey-38c3b4c58e6c6b86d6241183be1814bac2e037d2.tar.gz
libnitrokey-38c3b4c58e6c6b86d6241183be1814bac2e037d2.tar.bz2
Log current device ID
Allow logger to set global prefix Used to indicate current device Store USB path when used to connection as well Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'log.cc')
-rw-r--r--log.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/log.cc b/log.cc
index 263ddd7..e66feb0 100644
--- a/log.cc
+++ b/log.cc
@@ -26,6 +26,7 @@
#include "log.h"
#include <sstream>
+#include <NitrokeyManager.h>
namespace nitrokey {
namespace log {
@@ -33,6 +34,9 @@ namespace nitrokey {
Log *Log::mp_instance = nullptr;
StdlogHandler stdlog_handler;
+ std::string Log::prefix = "";
+
+
std::string LogHandler::loglevel_to_str(Loglevel lvl) {
switch (lvl) {
case Loglevel::DEBUG_L1:
@@ -52,8 +56,17 @@ namespace nitrokey {
}
void Log::operator()(const std::string &logstr, Loglevel lvl) {
- if (mp_loghandler != nullptr)
- if ((int) lvl <= (int) m_loglevel) mp_loghandler->print(logstr, lvl);
+ if (mp_loghandler != nullptr){
+ if ((int) lvl <= (int) m_loglevel) mp_loghandler->print(prefix+logstr, lvl);
+ }
+ }
+
+ void Log::setPrefix(const string prefix) {
+ if (!prefix.empty()){
+ Log::prefix = "["+prefix+"]";
+ } else {
+ Log::prefix = "";
+ }
}
void StdlogHandler::print(const std::string &str, Loglevel lvl) {