aboutsummaryrefslogtreecommitdiff
path: root/log.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-03-02 11:41:13 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2018-03-02 11:41:13 +0100
commit379daf936caa7fc8d7311a5dda101edb40d35ca5 (patch)
tree2d186dec6976b12a9f7b37e589c02703275a30ef /log.cc
parentd5486ba77235a874245fbee07a75cea89fa59ea2 (diff)
parentc3d615b659b608f3a1d624f6fc78c303efbe1f8e (diff)
downloadlibnitrokey-379daf936caa7fc8d7311a5dda101edb40d35ca5.tar.gz
libnitrokey-379daf936caa7fc8d7311a5dda101edb40d35ca5.tar.bz2
Merge branch 'wip-multiple_devices'
Allow to use multiple devices, iteratively. Storage only.
Diffstat (limited to 'log.cc')
-rw-r--r--log.cc19
1 files changed, 15 insertions, 4 deletions
diff --git a/log.cc b/log.cc
index 263ddd7..06acee7 100644
--- a/log.cc
+++ b/log.cc
@@ -19,11 +19,10 @@
* SPDX-License-Identifier: LGPL-3.0
*/
+#include "log.h"
#include <iostream>
-#include <string>
#include <ctime>
#include <iomanip>
-#include "log.h"
#include <sstream>
@@ -33,6 +32,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 +54,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 std::string prefix) {
+ if (!prefix.empty()){
+ Log::prefix = "["+prefix+"]";
+ } else {
+ Log::prefix = "";
+ }
}
void StdlogHandler::print(const std::string &str, Loglevel lvl) {