stderrlogger.cpp 799 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 31 32 33 34 35 36 37 38 39 40 41
#include "stderrlogger.hpp"
#include "common.hpp"
#include <iostream>
#include <string>
#include "trace.hpp"
#include "utils.hpp"

Stderrlogger::Stderrlogger(uid_t ruid, Log_type log_type):
	ILogger(ruid, log_type)
{
	TRACE_LOC_ON_MASK(LOGGING_MASK, 
			"Built Stderrlogger with log_type = %s\n",
			log_type_to_str(log_type).c_str());

}

Stderrlogger::~Stderrlogger()
{
}

void Stderrlogger::log(Log_type type, const string& message, int errnum)
{
	std::string msg_out;
	if(!prepare_log(type, message, msg_out, errnum))
		return;
	bool has_color = false;
	if(type == LOG_TYPE_ERROR)
	{
		std::cerr<<RED_TEXT;
		has_color = true;
	}
	else if(type == LOG_TYPE_WARNING)
	{
		std::cerr<<MAGENTA_TEXT;
		has_color = true;
	}

	std::cerr<<msg_out<<std::endl;
	if(has_color)
		std::cerr<<NEUTRAL_TEXT;
}