feat: improve ctors; mark LeveledSinks const
This commit is contained in:
parent
e1475e798e
commit
105aac9451
22
Log.cpp
22
Log.cpp
|
@ -19,9 +19,9 @@ namespace Log {
|
|||
// abstract base class for a log sink
|
||||
class Output {
|
||||
public:
|
||||
Output() {}
|
||||
Output(Level lvl_max) : lvl_max(lvl_max) {}
|
||||
virtual ~Output() {}
|
||||
Output() = default;
|
||||
explicit Output(Level lvl_max) : lvl_max{lvl_max} {}
|
||||
virtual ~Output() = default;
|
||||
|
||||
virtual void log(Level lvl, std::stringbuf* sbuf) {
|
||||
//aquire lock
|
||||
|
@ -52,7 +52,7 @@ protected:
|
|||
// logging to stdout/stderr
|
||||
class ConsoleOutput : public Output {
|
||||
public:
|
||||
ConsoleOutput() : Output() {}
|
||||
ConsoleOutput() = default;
|
||||
|
||||
virtual bool setColoredOutput(bool enabled) {
|
||||
// TODO: check the terminal's compatibility for colors
|
||||
|
@ -137,13 +137,13 @@ void log(Level lvl, std::stringbuf* strb) {
|
|||
}
|
||||
}
|
||||
|
||||
LeveledSink fatal{Level::fatal};
|
||||
LeveledSink error{Level::error};
|
||||
LeveledSink warn{Level::warn};
|
||||
LeveledSink note{Level::note};
|
||||
LeveledSink info{Level::info};
|
||||
LeveledSink debug{Level::debug};
|
||||
LeveledSink trace{Level::trace};
|
||||
const LeveledSink fatal{Level::fatal};
|
||||
const LeveledSink error{Level::error};
|
||||
const LeveledSink warn{Level::warn};
|
||||
const LeveledSink note{Level::note};
|
||||
const LeveledSink info{Level::info};
|
||||
const LeveledSink debug{Level::debug};
|
||||
const LeveledSink trace{Level::trace};
|
||||
|
||||
/*
|
||||
* class Entry
|
||||
|
|
23
Log.h
23
Log.h
|
@ -34,8 +34,11 @@ private:
|
|||
void addMetadataHeader();
|
||||
|
||||
public:
|
||||
Entry(Level lvl);
|
||||
explicit Entry(Level lvl);
|
||||
Entry(const Entry&) = delete;
|
||||
Entry& operator=(const Entry&) = delete;
|
||||
Entry(Entry&&) = default;
|
||||
Entry& operator=(Entry&&) = default;
|
||||
~Entry();
|
||||
|
||||
Level getLevel() const {
|
||||
|
@ -60,9 +63,9 @@ private:
|
|||
Level level;
|
||||
|
||||
public:
|
||||
LeveledSink(Level level) : level{level} {};
|
||||
explicit LeveledSink(Level level) noexcept : level{level} {};
|
||||
|
||||
template <typename T> Entry operator<<(const T& msg) {
|
||||
template <typename T> Entry operator<<(const T& msg) const {
|
||||
Entry entry{level};
|
||||
entry << msg;
|
||||
return entry;
|
||||
|
@ -70,12 +73,12 @@ public:
|
|||
};
|
||||
|
||||
// LeveledSinks
|
||||
extern LeveledSink fatal;
|
||||
extern LeveledSink error;
|
||||
extern LeveledSink warn;
|
||||
extern LeveledSink note;
|
||||
extern LeveledSink info;
|
||||
extern LeveledSink debug;
|
||||
extern LeveledSink trace;
|
||||
extern const LeveledSink fatal;
|
||||
extern const LeveledSink error;
|
||||
extern const LeveledSink warn;
|
||||
extern const LeveledSink note;
|
||||
extern const LeveledSink info;
|
||||
extern const LeveledSink debug;
|
||||
extern const LeveledSink trace;
|
||||
|
||||
} // namespace Log
|
||||
|
|
Loading…
Reference in New Issue