#ifndef TRACE_LOG_H
#define TRACE_LOG_H
#include <string>
#include <fstream>
#define LOG_INFO(...) {TraceLog::GetInst().Write("[INFO]", \
TraceLog::GetInst().Format("[%s][%s:%d]", __func__, __FILE__, __LINE__), \
TraceLog::GetInst().Format(__VA_ARGS__) \
);}
#define LOG_WARN(...) {TraceLog::GetInst().Write("[WARN]", \
TraceLog::GetInst().Format("[%s][%s:%d]", __func__, __FILE__, __LINE__), \
TraceLog::GetInst().Format(__VA_ARGS__) \
);}
#define LOG_ERROR(...) {TraceLog::GetInst().Write("[ERROR]", \
TraceLog::GetInst().Format("[%s][%s:%d]", __func__, __FILE__, __LINE__), \
TraceLog::GetInst().Format(__VA_ARGS__) \
);}
#define LOG_DEBUG(...) {TraceLog::GetInst().Write("[DEBUG]", \
TraceLog::GetInst().Format("[%s][%s:%d]", __func__, __FILE__, __LINE__), \
TraceLog::GetInst().Format(__VA_ARGS__) \
);}
class TraceLog
{
public:
static TraceLog& GetInst();
TraceLog(const TraceLog& log) = delete;
void Open(const std::string& path);
void Close();
void Write(const std::string& flag, const std::string& pos, const std::string& msg);
std::string Format(const char* fmt, ...);
private:
TraceLog() = default;
std::ofstream ofs_;
};
#endif