added logger name to output
This commit is contained in:
parent
66cfaa36bc
commit
ebae246a6b
@ -7,10 +7,12 @@
|
||||
//
|
||||
|
||||
#include "logger.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
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) << "] ";
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#define _logger_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user