#pragma once

#define MLOG_ALL(msg, level) {std::ostringstream mt_logstream;\
    mt_logstream << msg; \
    FileLogger::GetInstance().LogLine(level, mt_logstream, __FILE__, __FUNCTION__, __LINE__);};

#define MLOG_INFO(msg) MLOG_ALL(msg, "Info");
#define MLOG_ERROR(msg) MLOG_ALL(msg, "Error");

#include <memory>
#include <string>
#include <fstream>
#include <sstream>

class FileLogger
{
    std::string mWorkDirectory;
    std::string mFileName;
    std::ofstream mFileStream;

    FileLogger()
        :mWorkDirectory(),
         mFileName("MT_Log.txt"),
         mFileStream()
    {

    }

public:

    static FileLogger& GetInstance()
    {
        static FileLogger instance;
        return instance;
    }

    FileLogger(FileLogger const&) = delete;
    void operator=(FileLogger const&)  = delete;

    ~FileLogger();

    void SetWorkDirectory(const std::string& workDir);

    void SetFileName(const std::string& fileName);

    void Open();

    void Close();

    void LogLine(const std::ostringstream& line);

    void LogLine(const std::string& logType, const std::ostringstream& line, const std::string& fileName = "", const std::string& functionName = "", int lineNumber=-1);

};

using FileLoggerPtr = std::shared_ptr<FileLogger>;
