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;
}
本文解析了Log类在程序调试中的作用,介绍了如何使用Console进行信息输出,并强调了未来可能的改进。通过实例展示了如何设置不同级别日志,以及在`main()`函数中演示了Log类的使用。
3196

被折叠的 条评论
为什么被折叠?



