Output sf::err to a file like so.
static void Write(std::string message,std::ostream& stream)
{
if(isEnabled)
{
std::fstream file;
file.open(logFile.c_str(), std::ios::out | std::ios::app);
if (file.is_open())
{
file << message;
file << stream;
file << "\n";
file.close();
}
}
}
This particular error comes from not being able to load an image, I know why it cannot load the image, so I am not trying to solve that issue, I am just trying to get my Logger working with sf::err like above.
Follow up question, so it works, but only in certain cases in my code, if I wrap it in an if statement at all, it wont output to the file...
See the output, if I remove the if statement it will output to the file, if I leave it in all it will do is not print to the console but not output to the file.
// Enable Logging if in Debug Mode
if(_DEBUG)
{
// Base Name, Enabled, Has Date
Logger::Init("Soaring Steele",true,true);
}
else
{
// Base Name, Enabled, Has Date
Logger::Init("Soaring Steele",false,true);
}
// Redirect the standard error to a file, if logging is enabled.
// For some reason you cannt wrap an if statement around this or it fails to work right.
// So comment out if you dont want the standard error going here.
if(Logger::isEnabled)
{
std::ofstream file(Logger::logFile.c_str(), std::ios::app);
std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
}