libsclogging/logger.cpp

33 lines
826 B
C++
Raw Normal View History

//
// 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>
using namespace sc;
2020-04-29 16:54:58 +02:00
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) {
if (_topcall) {
write_prefix(level, file, line, func);
} else {
_topcall = true;
}
std::cerr << '\n';
}
}
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 << "() ";
std::cerr << '[' << loglevel_desc(level) << "] ";
}