Log类?https://www.bilibili.com/video/BV1VJ411M7WR?p=20
The Log class is for debugging purposes.
The Console is something built into the operating system so it will always work.
The code may need to be improved in future videos.
#include <iostream>
class Log{
private:
int m_level=LogLevelInfo;//the prefix indicates member variable so you can differentiate it from local variables
public:
const int LogLevelError =0;
const int LogLevelWarning =1;
const int LogLevelInfo =2;
public:
void Error(const char * msg){
if(m_level>=LogLevelError)
std::cout<<"[Error] "<<msg<<std::endl;
}
void Warning(const char * msg){
if(m_level>=LogLevelWarning)
std::cout<<"[Warning] "<<msg<<std::endl;
}
void Info(const char * msg){
if(m_level>=LogLevelInfo)
std::cout<<"[Info] "<<msg<<std::endl;
}
void SetLevel(int level){
m_level=level;
}
};
int main(){
Log log;
// log.SetLevel(log.LogLevelError);
log.Error("error test");
// log.SetLevel(log.LogLevelWarning);
log.Warning("warning test");
// log.SetLevel(log.LogLevelInfo);
log.Info("info test");
return 0;
}
|