2013-01-04 23:31:51 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <iostream>
|
2013-05-13 19:53:28 +00:00
|
|
|
#include "platform.h"
|
2013-01-04 23:31:51 +00:00
|
|
|
|
|
|
|
LogLevel Log::reportingLevel = LogInfo;
|
2013-01-08 02:24:59 +00:00
|
|
|
FILE* Log::file = NULL; //fopen(getLogPath().c_str(), "w");
|
2013-01-04 23:31:51 +00:00
|
|
|
|
|
|
|
LogLevel Log::getReportingLevel()
|
|
|
|
{
|
|
|
|
return reportingLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Log::getLogPath()
|
|
|
|
{
|
2013-05-13 19:53:28 +00:00
|
|
|
std::string home = getHomePath();
|
2013-01-04 23:31:51 +00:00
|
|
|
return home + "/.emulationstation/es_log.txt";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log::setReportingLevel(LogLevel level)
|
|
|
|
{
|
|
|
|
reportingLevel = level;
|
|
|
|
}
|
|
|
|
|
2013-01-08 02:24:59 +00:00
|
|
|
void Log::open()
|
|
|
|
{
|
|
|
|
file = fopen(getLogPath().c_str(), "w");
|
|
|
|
}
|
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
std::ostringstream& Log::get(LogLevel level)
|
|
|
|
{
|
|
|
|
os << "lvl" << level << ": \t";
|
|
|
|
messageLevel = level;
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log::flush()
|
|
|
|
{
|
|
|
|
fflush(getOutput());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log::close()
|
|
|
|
{
|
|
|
|
fclose(file);
|
|
|
|
file = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* Log::getOutput()
|
|
|
|
{
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log::~Log()
|
|
|
|
{
|
|
|
|
os << std::endl;
|
2013-01-08 02:24:59 +00:00
|
|
|
|
|
|
|
if(getOutput() == NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "ERROR - tried to write to log file before it was open!\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
fprintf(getOutput(), "%s", os.str().c_str());
|
|
|
|
|
|
|
|
//if it's an error, also print to console
|
2013-06-30 01:37:18 +00:00
|
|
|
//print all messages if using --debug
|
|
|
|
if(messageLevel == LogError || reportingLevel >= LogDebug)
|
2013-01-04 23:31:51 +00:00
|
|
|
fprintf(stderr, "%s", os.str().c_str());
|
|
|
|
}
|