/*
 * See the files COPYING and README for copyright information and how to reach 
 * the author.
 *
 *  $Id: logger-vdr.c,v 1.1 2006/04/17 19:03:45 lordjaxom Exp $
 */

#include "logger-vdr.h"
#include "proctools/format.h"
#include <iostream>
#include <vdr/tools.h>

namespace vdr_burn 
{

	using std::ofstream;
	using std::endl;
	using std::ios;

	ofstream logger_vdr::m_logfile;

	void logger_vdr::set_logfile(const std::string& filename)
	{
		m_logfile.close();
		m_logfile.clear();
		m_logfile.open(filename.c_str(), ios::out);
	}

	void logger_vdr::log(loglevel level, const std::string& message)
	{
		switch (level)
		{
		case level_error:
			esyslog("ERROR[%s]: %s", PLUGIN_NAME_I18N, message.c_str());
			break;

		case level_warning:
		case level_info:
			isyslog("%s: %s", PLUGIN_NAME_I18N, message.c_str());
			break;

		case level_debug:
			dsyslog("%s: %s", PLUGIN_NAME_I18N, message.c_str());
			break;

		default:
			m_logfile << message << endl;
			m_logfile.flush();
			break;
		}
	}

};
