暂时先这样,后面加文件和行号,再加打印参数
#ifndef __DR_SIMPLE_LOGGER_HH__
#define __DR_SIMPLE_LOGGER_HH__
#include <iostream>
#include <string>
namespace logger
{
void logger(std::string log);
void logger_warn (std::string log);
void logger_info (std::string log);
void logger_error (std::string log);
//TODO: add print params
void logger (std::string header,std::string color,std::string log)
{
std::string de_color = "\033[0m\n"; // default_color
std::string color_log = color + header + log + de_color;//TODO:filename and line number
std::cout << color_log;
}
void logger_info (std::string log)
{
std::string color = "\033[34m";//blue
std::string header = "[Warning]: ";
logger(header,color,log);
}
void logger_warn (std::string log)
{
std::string color = "\033[33m";//yellow
std::string header = "[Warning]: ";
logger(header,color,log);
}
void logger_error (std::string log)
{
std::string color = "\033[31m\033[5m";//red
std::string header = "[Error]: ";
logger(header,color,log);
}
} // namespace logger
#endif //__DR_SIMPLE_LOGGER_HH__
使用:
#include "logger.hh"
int main ()
{
logger::logger_warn ("warnnnnnnnnnnnnnnnnnnnnnn");
logger::logger_error ("errorrrrrrrrrrrrrrrrrrrrrr");
logger::logger_info ("infooooooooooooooooooo");
return 0;
}