/***********************************************************
This class is multithread safe
This class is specifically designed for keeping GameEngine logs
This class hence can only handle a single log file so never attempt to call initLog() twice
No constructor is avialbale for this class
The connection to the log file is closed when the program exits
When the program starts the initLog() must be called with the name of the log file
All the member functions in this class are static
************************************************************/

#pragma once
#include <fstream>
#include <mutex>
#include <string>

class Log
{
	static std::ofstream logFile;
	static bool fileOpen;
	static std::mutex writeLock;

	Log() = delete;
	template <typename T>
	static void print(T mssg)
	{
		logFile << " " << mssg;
	}
	static void log()
	{
		logFile << std::endl;
	}
	template <typename T, typename...Ts>
	static void log(const T &first, const Ts&... rest)
	{
		print(first);
		log(rest...);
	}

public:
	static void initLog(std::string fileName);

	template <typename T, typename...Ts>
	static void logWarning(const T &first, const Ts&... rest)
	{
		std::lock_guard<std::mutex> lock(writeLock);
		logFile << "[Warning]:";
		log(first, rest...);
	}

	template <typename T, typename...Ts>
	static void logError(const T &first, const Ts&... rest)
	{
		std::lock_guard<std::mutex> lock(writeLock);
		logFile << "[Error  ]:";
		log(first, rest...);
	}

	template <typename T, typename...Ts>
	static void logInfo(const T &first, const Ts&... rest)
	{
		std::lock_guard<std::mutex> lock(writeLock);
		logFile << "[Info   ]:";
		log(first, rest...);
	}
	~Log();
};



