add deleter
This commit is contained in:
parent
13559b181e
commit
6ba52c9f45
13
Log.cpp
13
Log.cpp
|
@ -186,6 +186,19 @@ Entry::~Entry() {
|
|||
log(lvl, ss.rdbuf());
|
||||
}
|
||||
|
||||
Deleter::Deleter() {
|
||||
if(refCount.fetch_add(1) == 0) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
Deleter::~Deleter() {
|
||||
if(refCount.fetch_sub(1) == 1) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
std::atomic<uint32_t> Deleter::refCount{0};
|
||||
|
||||
std::vector<Entry::MetaFunction> entryMetaFunctions;
|
||||
|
||||
std::ostream& defaultEntryMetaTime(std::ostream& os, const Entry& e) {
|
||||
|
|
10
Log.h
10
Log.h
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional> // std::function
|
||||
#include <sstream> // std::stringstream (buffer for log entries)
|
||||
#include <string>
|
||||
|
@ -100,6 +101,15 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
// class to automatically stop the logger on destruction
|
||||
class Deleter {
|
||||
public:
|
||||
Deleter();
|
||||
~Deleter();
|
||||
private:
|
||||
static std::atomic<uint32_t> refCount;
|
||||
};
|
||||
|
||||
extern std::vector<Entry::MetaFunction> entryMetaFunctions;
|
||||
|
||||
std::ostream& defaultEntryMetaTime(std::ostream&, const Entry&);
|
||||
|
|
Loading…
Reference in New Issue