57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#ifndef LOGGER_HPP
|
|
#define LOGGER_HPP
|
|
#include <string>
|
|
#include <fstream>
|
|
#include <ostream>
|
|
|
|
namespace Plains {
|
|
namespace Core {
|
|
|
|
using std::string;
|
|
using std::ofstream;
|
|
//using std::ostream;
|
|
//using std::streambuf;
|
|
|
|
class Logger {
|
|
public:
|
|
enum Level { DEBUG, INFO, WARN, FATAL };
|
|
Logger(Level logLevel);
|
|
~Logger();
|
|
void setLogLevel(Level level);
|
|
void log(Level lvl, const char* msg);
|
|
void log(Level lvl, const string& msg);
|
|
static const char commit = 0;
|
|
|
|
class Sink {
|
|
private:
|
|
bool lineIsPrefixed;
|
|
Logger& parent;
|
|
const Logger::Level level;
|
|
void prefixLine(bool resetToFalse = false);
|
|
public:
|
|
Sink(const Level level, Logger& parent);
|
|
void ln (const string& msg);
|
|
void ln (const char* msg);
|
|
Sink& operator<<(const char character);
|
|
Sink& operator<<(const string& msg);
|
|
Sink& operator<<(const char* msg);
|
|
Sink& operator<<(const unsigned long msg);
|
|
};
|
|
|
|
Sink debug;
|
|
Sink info;
|
|
Sink warn;
|
|
Sink fatal;
|
|
|
|
private:
|
|
enum Level logLevel;
|
|
ofstream* output;
|
|
static string genTimeStamp();
|
|
};
|
|
|
|
|
|
|
|
|
|
}}
|
|
#endif
|