diff --git a/Log.cpp b/Log.cpp index 24e758f..9f84977 100644 --- a/Log.cpp +++ b/Log.cpp @@ -1,12 +1,20 @@ #include "Log.h" /* - class Log -*/ + * class Log + */ -// static member +// static members std::vector Log::outputs; +Log::LeveledSink Log::fatal(Log::Level::FATAL); +Log::LeveledSink Log::error(Log::Level::ERROR); +Log::LeveledSink Log::warn(Log::Level::WARN); +Log::LeveledSink Log::note(Log::Level::NOTE); +Log::LeveledSink Log::info(Log::Level::INFO); +Log::LeveledSink Log::debug(Log::Level::DEBUG); +Log::LeveledSink Log::trace(Log::Level::TRACE); + void Log::init() { // add default console logger if (outputs.empty()) @@ -138,4 +146,6 @@ std::ostream* Log::FileOutput::getOs(Log::Level lvl) { if (lvl_min <= lvl && lvl <= lvl_max) return &ofs; return nullptr; -} \ No newline at end of file +} + +Log::LeveledSink::LeveledSink(Log::Level level) : level(level) {} diff --git a/Log.h b/Log.h index 1cc787c..b4666a5 100644 --- a/Log.h +++ b/Log.h @@ -95,51 +95,29 @@ public: } }; - template - static void fatal(const T& msg) { - Entry(FATAL) << msg; - } - static Entry fatal() { return Entry(FATAL); } + class LeveledSink { + private: + Log::Level level; + public: + LeveledSink(Log::Level level); - template - static void error(const T& msg) { - Entry(ERROR) << msg; - } - static Entry error() { return Entry(ERROR); } + template + Log::Entry operator<<(const T& msg) { + Log::Entry entry(level); + entry << msg; + return entry; + } + }; - template - static void warn(const T& msg) { - Entry(WARN) << msg; - } - static Entry warn() { return Entry(WARN); } + // LeveledSinks + static LeveledSink fatal; + static LeveledSink error; + static LeveledSink warn; + static LeveledSink note; + static LeveledSink info; + static LeveledSink debug; + static LeveledSink trace; - template - static void note(const T& msg) { - Entry(NOTE) << msg; - } - static Entry note() { return Entry(NOTE); } - - template - static void info(const T& msg) { - Entry(INFO) << msg; - } - static Entry info() { return Entry(INFO); } - - template - static void debug(const T& msg) { - Entry(DEBUG) << msg; - } - static Entry debug() { return Entry(DEBUG); } - - template - static void trace(const T& msg) { - Entry(TRACE) << msg; - } - static Entry trace() { return Entry(TRACE); } - - template - static void log(const T& msg, Level lvl) { - Entry(lvl) << msg; - } +private: static void log(Level lvl, std::stringbuf* strb); };