/*ABOUT logger.hthis headfile includes:class Logger { // helps you to logging! Logger(int m); Init the logger with m(ode),if you don't write this,it will be 0. void setmode(int m); Set the mode to m(ode),it will throw an error if m out of the range. int getmode(); Returns the id of the current mode. void switchLogging(); Switch the logging sign(yes to no,no to yes). bool isLogging(); Returns if it is logging. void sendMessage(string msg); Send a message likes XXX:XXX. void sendMessage(string msg,string moreInfo); Send a message with more information likes XXX:XXX(XXX).}*/#include <bits/stdc++.h>class Logger {
public : //constructorLogger(int);
//settingsvoid setmode(int m) {
if (0 <= m && m < ModeCnt) _mode = m;
else throw std::runtime_error("Invaild mode id");
}
int getmode() const {
return _mode;
}
void switchLogging() {
_openLogging = !_openLogging;
}
bool isLogging() {
return _openLogging;
}
//loggingvoid sendMessage(std::string msg) {
if (!_openLogging) return ;
std::cout << _nams[_mode] << ":" << msg << "\n";
}
void sendMessage(std::string msg,std::string moreInfo) {
if (!_openLogging) return ;
std::cout << _nams[_mode] << ":" << msg << "(" << moreInfo << ")" << "\n";
}
protected:const int ModeCnt = 4;
const std::vector<std::string> _nams = {"info","tip","warning","dangerous"};
private:int _mode;
/* id for _nams */bool _openLogging;
/* true:logging false:do not logging */
};
Logger::Logger(int m = 0) {
this->_mode = m;
this->_openLogging = true;
}