2020-04-29 15:27:14 +02:00
|
|
|
//
|
|
|
|
// logger.cpp
|
|
|
|
// libsclogging
|
|
|
|
//
|
|
|
|
// Created by Bob Polis at 2020-04-29
|
|
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "logger.hpp"
|
2020-04-29 16:54:58 +02:00
|
|
|
#include <unistd.h>
|
2020-04-29 15:27:14 +02:00
|
|
|
|
|
|
|
using namespace sc;
|
|
|
|
|
2020-04-29 16:54:58 +02:00
|
|
|
logger::logger(const std::string& name, loglevel level)
|
|
|
|
: _level(level), _name(name) {}
|
2020-04-29 15:27:14 +02:00
|
|
|
|
2020-04-29 16:40:04 +02:00
|
|
|
void logger::msg(loglevel level, const char* file, int line, const char* func) {
|
2020-04-29 15:27:14 +02:00
|
|
|
if (level >= _level) {
|
|
|
|
if (_topcall) {
|
2020-04-29 16:40:04 +02:00
|
|
|
write_prefix(level, file, line, func);
|
2020-04-29 15:27:14 +02:00
|
|
|
} else {
|
|
|
|
_topcall = true;
|
|
|
|
}
|
|
|
|
std::cerr << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 16:40:04 +02:00
|
|
|
void logger::write_prefix(loglevel level, const char* file, int line, const char* func) {
|
2020-04-29 16:54:58 +02:00
|
|
|
std::cerr << _name << "[" << ::getpid() << "] ";
|
|
|
|
std::cerr << file << ":" << line << " " << func << "() ";
|
2020-04-29 16:40:04 +02:00
|
|
|
std::cerr << '[' << loglevel_desc(level) << "] ";
|
2020-04-29 15:27:14 +02:00
|
|
|
}
|