53 #define CRITICAL(x,y) std::clog << fv::util::LogPriority::kLogCritical << __FILE__ << "@L" << __LINE__ << " :: " << x << std::flush; std::cout << "Errors encountered! See log file for details."<<std::endl;exit(y) 54 #define ERROR(x) std::clog << fv::util::LogPriority::kLogError << __FILE__ << "@L" << __LINE__ << " :: " << x << std::flush 55 #define WARNING(x) std::clog << fv::util::LogPriority::kLogWarning << x << std::flush 56 #define INFO(x) std::clog << fv::util::LogPriority::kLogInfo << x << std::flush 57 #define DEBUG(x) std::clog << fv::util::LogPriority::kLogDebug << __FILE__ << "@L" << __LINE__ << " :: " << x << std::flush 62 std::ostream& operator<< (std::ostream& os,
const LogPriority& log_priority);
64 class Log :
public std::basic_streambuf<char, std::char_traits<char> > {
67 std::ofstream logfile;
68 LogPriority priority_curr;
69 LogPriority priority_set;
70 inline static Log* singleton =
nullptr;
71 const std::map<LogPriority,std::string> name_map = {{kLogEmergency,
"EMERGENCY"},
73 {kLogCritical,
"CRITICAL"},
75 {kLogWarning,
"WARNING"},
76 {kLogNotice,
"NOTICE"},
78 {kLogDebug,
"DEBUG"}};
80 friend std::ostream& operator<< (std::ostream& os,
const LogPriority& log_priority){
81 static_cast<Log *
>(os.rdbuf())->priority_curr = log_priority;
86 if (buffer_.length()) {
87 if (priority_curr >= priority_set){
88 logfile << name_map.at(priority_curr) <<
": " << buffer_ << std::endl << std::flush;
97 buffer_ +=
static_cast<char>(c);
104 explicit Log(std::string filename, LogPriority priority)
105 :logfile(filename, std::ofstream::out){
106 priority_set = priority;
107 priority_curr = kLogDebug;
110 static Log& init_logger(std::string filename, LogPriority priority){
111 if (singleton ==
nullptr){
112 singleton =
new Log(filename, priority);
113 std::cout <<
"Writing log data to " << filename << std::endl;
114 std::clog.rdbuf(singleton);
Definition: argparse.hpp:39