From ebae246a6b654f3c92eae69c2a9e4558e6133f0b Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 29 Apr 2020 16:54:58 +0200 Subject: [PATCH] added logger name to output --- logger.cpp | 7 +++++-- logger.hpp | 4 +++- tester/main.cpp | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/logger.cpp b/logger.cpp index 5dc1bc0..2494c2c 100644 --- a/logger.cpp +++ b/logger.cpp @@ -7,10 +7,12 @@ // #include "logger.hpp" +#include using namespace sc; -logger::logger(loglevel level) : _level(level) {} +logger::logger(const std::string& name, loglevel level) + : _level(level), _name(name) {} void logger::msg(loglevel level, const char* file, int line, const char* func) { if (level >= _level) { @@ -24,6 +26,7 @@ void logger::msg(loglevel level, const char* file, int line, const char* func) { } void logger::write_prefix(loglevel level, const char* file, int line, const char* func) { - std::cerr << file << ":" << line << ", " << func << "() "; + std::cerr << _name << "[" << ::getpid() << "] "; + std::cerr << file << ":" << line << " " << func << "() "; std::cerr << '[' << loglevel_desc(level) << "] "; } diff --git a/logger.hpp b/logger.hpp index 5a2062d..629b7ae 100644 --- a/logger.hpp +++ b/logger.hpp @@ -10,6 +10,7 @@ #define _logger_H_ #include +#include namespace sc { @@ -40,7 +41,7 @@ namespace sc { class logger { public: - logger(loglevel level); + logger(const std::string& name, loglevel level); void msg(loglevel level, const char* file, int line, const char* func); @@ -68,6 +69,7 @@ namespace sc { loglevel _level {loglevel::info}; bool _topcall {true}; + std::string _name; }; } diff --git a/tester/main.cpp b/tester/main.cpp index 8537260..018e108 100644 --- a/tester/main.cpp +++ b/tester/main.cpp @@ -59,7 +59,7 @@ int main(int argc, const char * argv[]) { } } std::cout << "hello, tester\n"; - sc::logger logger(sc::loglevel::debug); + sc::logger logger("tester", sc::loglevel::debug); _info(logger, 42, " = ", 6, " x ", 7); _debug(logger, "efkes proberen"); } catch (const std::exception& ex) {