Blame synfig-core/src/synfig/debug/log.cpp

371bd9
/* === S Y N F I G ========================================================= */
371bd9
/*!	\file debug/log.cpp
371bd9
**	\brief Template File
371bd9
**
371bd9
**	$Id$
371bd9
**
371bd9
**	\legal
371bd9
**	......... ... 2015 Ivan Mahonin
371bd9
**
371bd9
**	This package is free software; you can redistribute it and/or
371bd9
**	modify it under the terms of the GNU General Public License as
371bd9
**	published by the Free Software Foundation; either version 2 of
371bd9
**	the License, or (at your option) any later version.
371bd9
**
371bd9
**	This package is distributed in the hope that it will be useful,
371bd9
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
371bd9
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
371bd9
**	General Public License for more details.
371bd9
**	\endlegal
371bd9
*/
371bd9
/* ========================================================================= */
371bd9
371bd9
/* === H E A D E R S ======================================================= */
371bd9
371bd9
#ifdef USING_PCH
371bd9
#	include "pch.h"
371bd9
#else
371bd9
#ifdef HAVE_CONFIG_H
371bd9
#	include <config.h></config.h>
371bd9
#endif
371bd9
371bd9
#include <cstdlib></cstdlib>
371bd9
371bd9
#include <fstream></fstream>
371bd9
371bd9
#include "log.h"
371bd9
371bd9
#include <synfig general.h=""></synfig>
371bd9
371bd9
#endif
371bd9
371bd9
/* === U S I N G =========================================================== */
371bd9
371bd9
using namespace etl;
371bd9
using namespace synfig;
371bd9
using namespace debug;
371bd9
371bd9
/* === M A C R O S ========================================================= */
371bd9
371bd9
/* === G L O B A L S ======================================================= */
371bd9
371bd9
/* === P R O C E D U R E S ================================================= */
371bd9
371bd9
/* === M E T H O D S ======================================================= */
371bd9
Rodolfo Ribeiro Gomes cfe072
std::mutex Log::mutex;
371bd9
371bd9
void Log::append_line_to_file(const String &logfile, const String &str)
371bd9
{
Rodolfo Ribeiro Gomes cfe072
	std::lock_guard<std::mutex> lock(mutex);</std::mutex>
371bd9
	std::ofstream f(logfile.c_str(), std::ios_base::app);
371bd9
	f << str << std::endl;
371bd9
}
371bd9
371bd9
void
371bd9
Log::error(const String &logfile, const String &str)
371bd9
{
371bd9
	if (logfile.empty()) synfig::error(str); else append_line_to_file(logfile, str);
371bd9
}
371bd9
371bd9
void
371bd9
Log::warning(const String &logfile, const String &str)
371bd9
{
371bd9
	if (logfile.empty()) synfig::warning(str); else append_line_to_file(logfile, str);
371bd9
}
371bd9
371bd9
void
371bd9
Log::info(const String &logfile, const String &str)
371bd9
{
371bd9
	if (logfile.empty()) synfig::info(str); else append_line_to_file(logfile, str);
371bd9
}
371bd9
371bd9
void
371bd9
Log::error(const String &logfile, const char *format,...)
371bd9
{
371bd9
	va_list args;
371bd9
	va_start(args,format);
371bd9
	error(logfile, vstrprintf(format,args));
371bd9
}
371bd9
371bd9
void
371bd9
Log::warning(const String &logfile, const char *format,...)
371bd9
{
371bd9
	va_list args;
371bd9
	va_start(args,format);
69c355
	warning(logfile, vstrprintf(format,args));
371bd9
}
371bd9
371bd9
void
371bd9
Log::info(const String &logfile, const char *format,...)
371bd9
{
371bd9
	va_list args;
371bd9
	va_start(args,format);
69c355
	info(logfile, vstrprintf(format,args));
371bd9
}