#include "Logger.h"

#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

std::string Logger::_filename = "log.txt";
int Logger::_level = LOG_INFO;
Logger* Logger::_instance = NULL;
std::ostringstream Logger::_oss;

Logger::Logger():
	_file(_filename.c_str())
{
}

Logger::~Logger()
{
	_file.close();
}

Logger* Logger::getInstance()
{
	if (_instance == NULL) _instance = new Logger();
	return _instance;
}

void Logger::log(int severity)
{
	if (severity >= _level) {
		_file << _oss.str() << '\n';
		cout << _oss.str() << endl;
	}
	_file.flush();
	_oss.clear();
	_oss.str("");
}
