diff options
Diffstat (limited to 'log.cc')
-rw-r--r-- | log.cc | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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) { |