#pragma once

//#ifdef WIN32
//#ifdef _MT
//#ifndef _DLL
//#ifdef _DEBUG
//#pragma comment(lib, "logger-mtd.lib") // _MT && _DEBUG
//#else
//#pragma comment(lib, "logger-mt.lib") // _MT
//#endif
//#else
//#ifdef _DEBUG
//#pragma comment(lib, "logger-mdd.lib") // _MT && _DLL && _DEBUG
//#else
//#pragma comment(lib, "logger-md.lib") // _MT && _DLL
//#endif
//#endif
//#endif
//#endif

#include <string>
#include <thread>
#include <windows.h>

#include "threadsafe_queue.hpp"

namespace tools
{

class logger
{
public:
	enum log_level
	{
		LVTRACK,
		LVDEBUG,
		LVWARN,
		LVERROR,
		LVFATAL,
		LVNORMAL
	};

	logger();
	logger(const std::string filename,const std::string filetype);
	virtual ~logger();

	void	set_level(const log_level& level);

	int		open(const std::string filename, const std::string filetype);
	void	write(const char* msg, ...);
	void	write(const log_level& level, const char* msg, ...);
	void	fsync();
	void	stop();
	bool    startflag() { return m_run; }
private:
	void	processor();
	std::thread	m_proc;

	struct raw_log
	{
		SYSTEMTIME	time;
		std::string	log;
		log_level	level;
	};

	threadsafe_queue<raw_log>	m_req_que;
	bool	m_run;
	HANDLE	m_hfile;
	log_level	m_curlv;
	unsigned int  m_last_day;
	std::string   m_filename;
	std::string   m_filetype;
};

};