filelogger.cpp 741 Bytes
Newer Older
Swann Perarnau's avatar
Swann Perarnau committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include "filelogger.hpp"
#include "common.hpp"
#include <string>
#include "utils.hpp"
#include "trace.hpp"

Filelogger::Filelogger(uid_t ruid, const string& filename, Log_type log_type,
		bool append):
	ILogger(ruid, log_type)
{
	std::ios_base::openmode mode = std::ofstream::out;
	if(append)
		mode |= std::ofstream::app;
	_file.open (filename.c_str(), mode);
	TRACE_LOC_ON_MASK(LOGGING_MASK, 
			"Built Filelogger with log_type = %s; and filename = %s\n",
			log_type_to_str(log_type).c_str(), filename.c_str());
}

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

void Filelogger::log(Log_type type, const string& message, int errnum)
{
	std::string msg_out;
	if(prepare_log(type, message, msg_out, errnum))
		_file<<msg_out<<std::endl;
}