WIP
This commit is contained in:
parent
762cc48220
commit
8169db351e
22
Log.h
22
Log.h
|
@ -8,7 +8,7 @@
|
|||
#include <vector> // list of outputs
|
||||
|
||||
class Log {
|
||||
public:
|
||||
public:
|
||||
enum Level { OFF = 0, FATAL, ERROR, WARN, NOTE, INFO, DEBUG, TRACE };
|
||||
|
||||
// delete ctors as this class is used via static methods only
|
||||
|
@ -22,17 +22,17 @@ class Log {
|
|||
// close all output streams
|
||||
static void stop();
|
||||
|
||||
private:
|
||||
private:
|
||||
// abstract base class for a log sink
|
||||
class Output {
|
||||
public:
|
||||
public:
|
||||
Output();
|
||||
Output(Log::Level lvl_max);
|
||||
virtual ~Output();
|
||||
virtual void log(Log::Level lvl, std::stringbuf* sbuf);
|
||||
virtual void setLogLevel(Log::Level lvl);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
Log::Level lvl_max = INFO;
|
||||
// returns the correct ostream for the given log-level
|
||||
// or returns nullptr if no ostream is set/enabled for this level
|
||||
|
@ -42,11 +42,11 @@ class Log {
|
|||
|
||||
// logging to stdout/stderr
|
||||
class ConsoleOutput : public Output {
|
||||
public:
|
||||
public:
|
||||
ConsoleOutput();
|
||||
virtual bool setColoredOutput(bool enabled);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::ostream* osStd = &std::cout;
|
||||
std::ostream* osErr = &std::cerr;
|
||||
bool coloredOutput;
|
||||
|
@ -55,11 +55,11 @@ class Log {
|
|||
};
|
||||
|
||||
class FileOutput : public Output {
|
||||
public:
|
||||
public:
|
||||
FileOutput(const std::string& filename, Log::Level lvl_max);
|
||||
FileOutput(const std::string& filename, Log::Level lvl_min, Log::Level lvl_max);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string filename;
|
||||
std::ofstream ofs;
|
||||
Log::Level lvl_min = FATAL;
|
||||
|
@ -68,7 +68,7 @@ class Log {
|
|||
|
||||
static std::vector<Output*> outputs;
|
||||
|
||||
public:
|
||||
public:
|
||||
static void addLogfile(const std::string& filename, Level max);
|
||||
static void addLogfile(const std::string& filename, Level min, Level max);
|
||||
|
||||
|
@ -79,11 +79,11 @@ class Log {
|
|||
// by concatenation with the << operator
|
||||
// Inspired from https://stackoverflow.com/a/8337882
|
||||
class Entry {
|
||||
private:
|
||||
private:
|
||||
std::stringstream ss;
|
||||
Log::Level lvl;
|
||||
|
||||
public:
|
||||
public:
|
||||
Entry(Log::Level lvl) : lvl(lvl) {}
|
||||
Entry(Entry&&) = default;
|
||||
~Entry() { Log::log(lvl, ss.rdbuf()); }
|
||||
|
|
Loading…
Reference in New Issue