#pragma once

#include <string>
#include <vector>
#include "spdlog/spdlog.h"

//#define _X_OPEN_LOG_
#define _X_OPEN_LOG_
#ifdef _X_OPEN_LOG_
#define X_TRACE(str) XLogMgr::GetInstance()->Log(str,spdlog::level::trace,__FUNCTION__)
#define X_TRACE(str) XLogMgr::GetInstance()->Log(str,spdlog::level::trace,__FUNCTION__)
#define X_DEBUG(str) XLogMgr::GetInstance()->Log(str,spdlog::level::debug,__FUNCTION__)
#define X_INFO(str) XLogMgr::GetInstance()->Log(str,spdlog::level::info,__FUNCTION__)
#define X_WARN(str) XLogMgr::GetInstance()->Log(str,spdlog::level::warn,__FUNCTION__)
#define X_ERR(str) XLogMgr::GetInstance()->Log(str,spdlog::level::err,__FUNCTION__)
#else
#define X_TRACE(str) 
#define X_DEBUG(str) 
#define X_INFO(str) 
#define X_WARN(str) 
#define X_ERR(str) 
#endif

#define XLog(str) X_TRACE(str)

using namespace std;
namespace spd = spdlog;

class XLogMgr
{
public:
	static XLogMgr*	GetInstance()
	{
		if (m_instance == nullptr)
		{
			m_instance = new XLogMgr();
		}
		return m_instance;
	}
	static void Releace()
	{
		if (m_instance)
		{
			delete m_instance;
			m_instance = nullptr;
		}
	}
	string						SC_Trace(vector<string> vParam);
	string						SC_Debug(vector<string> vParam);
	string						SC_Info(vector<string> vParam);
	string						SC_Warn(vector<string> vParam);
	string						SC_Err(vector<string> vParam);

	string						Log(const string sInfo, int nLevel = spd::level::trace, char* sFunc = nullptr);
	string						Log(const char* sInfo, int nLevel = spd::level::trace, char* sFunc = nullptr);
	void                        FlushLog();

private:
	void						XInit();
	static XLogMgr* m_instance;
	XLogMgr();
	~XLogMgr();
private:
	shared_ptr<spd::logger>		m_logger;
	string						m_FileName;
};

