40 lines
854 B
C++
40 lines
854 B
C++
#ifndef INVENTORY_LOG_HH_
|
|
#define INVENTORY_LOG_HH_
|
|
#include "logstream.hh"
|
|
#include "cxx-semantics.hh"
|
|
#include <memory>
|
|
|
|
#define LIBINVDB_LOG(lvl, str) Log::instance()(lvl, "[" + \
|
|
std::string(__func__) + " @ " + std::string(__FILE__) + ":" + \
|
|
std::to_string(__LINE__) + "] " + std::string(str))
|
|
|
|
namespace inventory {
|
|
|
|
class Log : public semantics::singleton<Log> {
|
|
public:
|
|
Log()
|
|
: m_loglevel(Loglevel::WARNING) {}
|
|
|
|
void set_stream(std::shared_ptr<Logstream> stream) {
|
|
mp_logstream = stream;
|
|
}
|
|
|
|
void set_loglevel(Loglevel lvl) {
|
|
m_loglevel = lvl;
|
|
}
|
|
|
|
void operator()(Loglevel lvl, const std::string &msg) {
|
|
if ((int)(lvl) <= (int)(m_loglevel))
|
|
(*mp_logstream)(lvl, msg);
|
|
}
|
|
|
|
private:
|
|
static std::shared_ptr<Logstream> mp_logstream;
|
|
|
|
Loglevel m_loglevel;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|